dougmarkham
Active Member
- Joined
- Jul 19, 2016
- Messages
- 252
- Office Version
- 365
- Platform
- Windows
Hi Folks,
I wish to open another excel spreadsheet via vba; however, the spreadsheet in question is a *.xltm file.
Currently I have this code to open a workboook:
First issue:
On running the macro, excel says the file cannot be found. Due to previous issues with referring to *.xltm files, my understanding is that when referring to an *.xltm file in vba, you don't add the file extension (just enclose it in speech marks). However, on running, the above vba code returns the error: file cannot be found. I did a test by replacing sFile = sPath & "abc" with sFile = sPath & "abc.xltm" but the same error came up. Please would you explain is wrong with my code?
Second issue: one that I expect to happen if I can get the macro to work (but may not be an issue)
Due to the macros within abc.xltm referring to the open workbook, I need the xltm file to open 'as if double-clicked upon' i.e., so that the open workbook will be abc1.xltm. Do I need to modify the above VBA code to open the abc.xltm file in such a way that it opens as abc1.xltm? If so, what code might achieve this?
Kind regards,
Doug.
I wish to open another excel spreadsheet via vba; however, the spreadsheet in question is a *.xltm file.
Currently I have this code to open a workboook:
Code:
Sub openwb() Dim sPath As String, sFile As String
Dim wb As Workbook
sPath = "C:\Users\dougmarkham\Desktop\"
sFile = sPath & "abc"
Set wb = Workbooks.Open(sFile)
End Sub
First issue:
On running the macro, excel says the file cannot be found. Due to previous issues with referring to *.xltm files, my understanding is that when referring to an *.xltm file in vba, you don't add the file extension (just enclose it in speech marks). However, on running, the above vba code returns the error: file cannot be found. I did a test by replacing sFile = sPath & "abc" with sFile = sPath & "abc.xltm" but the same error came up. Please would you explain is wrong with my code?
Second issue: one that I expect to happen if I can get the macro to work (but may not be an issue)
Due to the macros within abc.xltm referring to the open workbook, I need the xltm file to open 'as if double-clicked upon' i.e., so that the open workbook will be abc1.xltm. Do I need to modify the above VBA code to open the abc.xltm file in such a way that it opens as abc1.xltm? If so, what code might achieve this?
Kind regards,
Doug.