View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Barb Reinhardt Barb Reinhardt is offline
external usenet poster
 
Posts: 3,355
Default Help with GetFileName in code

I'd make sure you've got

Dim RFDSFile as String

in your original code. I generally put Option Explicit before any Subs in
each module so that it forces me to declare all variables. Some don't like
to play nicely if not declared properly.
--
HTH,
Barb Reinhardt




"Ayo" wrote:

I am having a problem with this line in my code:
Set f = fs.GetFileName(RFDSFile)
A Type mismatch error message.
Any ideas?
=RFDSFile is a filepath

Sub RFDS_File(RFDSFile As String)
Dim fs, f

Workbooks.Open RFDSFile, ReadOnly:=True
Sheets("RFDS").Select
Worksheets("RFDS").Copy After:=Workbooks("RFDS Tracker GA Market_Form
4C.xls").Sheets("RFDS Tracker (2)")
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFileName(RFDSFile)
Workbooks(f).Close SaveChanges:=False

'Extract_RFDSData

'''''''''''' DELETE RFDS SHEET '''''''''''''''''''''''''''''''''''''''''''''''
Dim sh As Worksheet
Application.DisplayAlerts = False
For Each sh In Worksheets
If Left(sh.Name, 4) = "RFDS" Then
sh.Select
ActiveWindow.SelectedSheets.Delete
End If
Next sh
Worksheets("RFDS Tracker").Range("A4").Select
End Sub