Edit Macro to Open Specific File Automatically

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,163
I am using this code to get me to a path then I click on the file I want and it opens it and makes it a .csv file. Then my code does stuff with it and closes it. My question is, do I even have to click on it? Can I get the macro to automatically open the file. Note the "NewestFolderInThePath" is a function that open me up to the "newest" created folder in the path. From there I double click file.

Code:
NewestFolderInThePath = ReturnNewestFolder("\\datawhse\root\LAW81\LAWSON\print\RBLEVINS2\anrvwfins\1\")
   Path = "\\datawhse\root\LAW81\LAWSON\print\RBLEVINS2\anrvwfins\1\"
    
    TheFile = Path & NewestFolderInThePath
    CreateObject("WScript.Shell").CurrentDirectory = TheFile
    
    TheFile = Application.GetOpenFilename("Excel Files (*.*), *.*", , "Open Balance Sheet File FRPMBSDTL")
If TheFile = "False" Then
      continue = MsgBox("Do you want to Continue to IS Download?", _
                    vbInformation + vbYesNo, _
                    "Continue?")

If continue = 6 Then GoTo IncSt
If continue = 7 Then Exit Sub
End If
      Oldfilename = TheFile

    ' Separate the file path and file name
      BS = InStrRev(Oldfilename, "\")
      Oldfilepath = Left(Oldfilename, BS)
      Newfilename = Right(Oldfilename, Len(Oldfilename) - BS)
    
    ' Add the CSV extension to the file name
      Dot = InStr(1, Newfilename, ".")
      Newfilename = Oldfilepath & Left(Newfilename, Dot) & "csv"
    
    ' Rename the file
      Name Oldfilename As Newfilename

    Workbooks.Open Filename:=Newfilename
     
    Set OpenA = Workbooks(Workbooks.Count)
 
Well I got it, but now this part is jacked up saying runtime error 53 file not found.

Code:
Name Oldfilename As Newfilename


Code:
NewestFolderInThePath = ReturnNewestFolder("\\datawhse\root\LAW81\LAWSON\print\RBLEVINS2\anrvwfins\1\")
   Path = "\\datawhse\root\LAW81\LAWSON\print\RBLEVINS2\anrvwfins\1\"
    
    TheFile = Path & NewestFolderInThePath & "\SSFRPMBSDTL"
    
    
    Workbooks.Open Filename:=TheFile
If TheFile = "False" Then
      continue = MsgBox("Do you want to Continue to IS Download?", _
                    vbInformation + vbYesNo, _
                    "Continue?")

If continue = 6 Then GoTo IncSt
If continue = 7 Then Exit Sub
End If
      Oldfilename = TheFile

    ' Separate the file path and file name
      BS = InStrRev(Oldfilename, "\")
      Oldfilepath = Left(Oldfilename, BS)
      Newfilename = Right(Oldfilename, Len(Oldfilename) - BS)
    
    ' Add the CSV extension to the file name
      Dot = InStr(1, Newfilename, ".")
      Newfilename = Oldfilepath & Left(Newfilename, Dot) & "csv"
    
    ' Rename the file
      Name Oldfilename As Newfilename

    Workbooks.Open Filename:=Newfilename
     
    Set OpenA = Workbooks(Workbooks.Count)
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I've been working on it for awhile now but can't get anything to work.
any ideas anyone??

ps: recap: the code I posted 1st worked perfect. I am wanting to change it though so I don't have to actually click (select) the file to open. I want to make the macro know which one to open and automatically do it.
No luck so far.
 
Upvote 0
I've been working on it for awhile now but can't get anything to work.
any ideas anyone??

ps: recap: the code I posted 1st worked perfect. I am wanting to change it though so I don't have to actually click (select) the file to open. I want to make the macro know which one to open and automatically do it.
No luck so far.

Hello erock24,

I have similar issue and I tried to search for codes to open specific files automatically but to no avail. I am using Excel 2010. Could you please help me?
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top