Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Help with GetFileName in code

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

  #2   Report Post  
Posted to microsoft.public.excel.misc
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

  #3   Report Post  
Posted to microsoft.public.excel.misc
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Help with GetFileName in code

This is the originalcode:
Private Sub cmdExtractData_Click()
Me.Hide
If Me.opt_File.Value = True Then
RFDS_File Me.txtFilePath.Value
ElseIf Me.opt_Folder.Value = True Then
Run "DoIt"
Application.ScreenUpdating = False
RFDS_Folder Me.txtFilePath.Value
Run "DoIt"
End If
End Sub

Me.txtFilePath.Value contains the file path

"Barb Reinhardt" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Help with GetFileName in code

fs.getfilename will return a string. So you don't need (and can't use) "Set".

f = fs.GetFileName(RFDSFile)

But you don't need FSO to return the name of the file, either.

Dim RFDSWkbk as workbook
....

set rfdswkbk = workbooks.open(filename:=rfdsfile,readonly:=true)
msgbox rfdswkbk.name 'is sufficient
or avoid the name completely later:
rfdswkbk.close SaveChanges:=False

Or you could use use instrrev() to pick out the everything from the last \ in
the filename.

f = Mid(RFDSFile, InStrRev(RFDSFile, "\", -1, vbTextCompare) + 1)

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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
Convert a Number Code to a Text Code Traye Excel Discussion (Misc queries) 3 April 6th 07 09:54 PM
Code expantion , with code! Arran Excel Discussion (Misc queries) 7 January 14th 07 01:05 AM
Unprotect Code Module in Code Damien Excel Discussion (Misc queries) 2 April 18th 06 03:10 PM
copying vba code to a standard code module 1vagrowr Excel Discussion (Misc queries) 2 November 23rd 05 04:00 PM


All times are GMT +1. The time now is 01:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"