VBA to open another abc.xltm file so that it opens as abc1.xltm

dougmarkham

Active Member
Joined
Jul 19, 2016
Messages
252
Office Version
  1. 365
Platform
  1. 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:

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.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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