I would like to use the GetOpenFilename method to open up to 100 files in a shared folder. It seems that I need to change the drive to make it work but I can’t get the syntax right. The shared folder was created on a PC named “PC1” and the shared folder name is “PC1-DATA”.
ChDrive “shared pc name” or ChDrive “shared pc name” doesn’t work. Strangely ChDrive “Server name:shared pc name” doesn’t generate an error message but this still returns the default path on the local machine. I expected this code to work but it doesn’t like the ChDrive “PC1”.
Sub SharedImport()
Dim wb as Integer
Dim FileToImport
ChDrive “PC1”
ChDir “PC1PC1-DATA”
FileToImport = Application.GetOpenFilename(“Report File (*.rpt), *.rpt”, , “Import report files into Excel”, , True)
For wb = 1 To UBound(FileToImport)
Workbooks.OpenText FileName:=FileToImport(wb), Origin:=xlWindows, StartRow:=1, Type:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1))
Next wb
End Sub
If I use the macro recorder it simply gives me “ChDir shared pc nameshared folder name”. This doesn’t work if you don’t manually move to the shared folder first. The same holds true if I use Application.DefaultFilePath = “shared pc nameshared folder name”.
I can use workbooks.open filename:= “shared pc nameshared folder namefile name” to open a single file but don’t know how make it work with the GetopenFilename method with multselect enabled.
I’m stuck on this one & really would like to make it work.
Thanks – John