Trying to cobble together two bis of code (Unsuccessfully)

D

Diddy

Hi everyone,

I'm at that stage where I'm probably a bit dangerous. I've recorded macros
and played with them, copied the lovely code from websites and played with it
etc.

Can I say thank you to Ron de Bruin for his code from MergeExamples which is
fantastic; does exactly what I want but loses me completely when I try to
work out what it does.

I'm using RDB_Copy_Sheet in the "Get_Sheet_Macro" module
http://www.rondebruin.nl/fso.htm with Excel 2003 but I think I need to
unprotect the sheets in the books in the source folder.

So, I tried reusing the bit of code that browses for the folder and adding a
do while loop but get a runtime error 13 type mismatch

Here's the code (I'm not adding RDB function that is in another module)
- so embarrassing to put this - shows exactly how much I don't understand

Sub unprotectshts()
'copied from RDB
Dim myFiles As Variant
Dim myCountOfFiles As Long
Dim oApp As Object
Dim oFolder As Variant

Set oApp = CreateObject("Shell.Application")

'Browse to the folder
Set oFolder = oApp.BrowseForFolder(0, "Select folder", 512)
If Not oFolder Is Nothing Then

myCountOfFiles = Get_File_Names( _
MyPath:=oFolder.Self.Path, _
Subfolders:=False, _
ExtStr:="*.xl*", _
myReturnedFiles:=myFiles)
End If

If myCountOfFiles = 0 Then
MsgBox "No files that match the ExtStr in this folder"
Exit Sub
End If
'End of copied from RDB
Do While myCountOfFiles <> 0

' Trying to get it to display a message box
'that will show sub looping though folders
'will change for unprotect sheets bit if I ever get this to work

MsgBox MyPath

Loop
End Sub

If anyone can help me that would be great

Thanks
 
D

Diddy

Hi Keith,

Thanks for responding :)

I don't think so

I'm probably missing something really important

Thanks anyway
 
K

Keith74

Hi

The reason i said that is that the msgbox will only accept a variable
it can display as a string, i'm guessing you're getting the "type
mismatch" on the message box. Put a watch on myPath and step through
the code to see what value myPath has. It looks like myPath is
probably the wrong variable to be using.
 
D

Diddy

Hi Keith,

You are right

Watch : : mypath : <Expression not defined in context> : Empty :
UnProtSheetsinBooksInFolder.unprotectshts

I'm lost !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top