pretzels04
pretzels04

Reputation: 33

EXCEL VBA: opening XLSM excel using vba

i cant figure out my error in my codes

If cboUnit.Text = "MARINER" Then
Application.ScreenUpdating = False
Application.Workbooks.Open Filename:=ThisWorkbook.Path & "\UNIT" & "\MARINER"
ThisWorkbook.Activate
Workbooks("TOUKEI DATA REPORT GRAPHING").Close
End If

i just want to open xlsm file which is on the folder unit but i always got an error:

runtime error '1004' the file this getting is 'xlsx' extension

Upvotes: 1

Views: 12896

Answers (1)

peege
peege

Reputation: 2477

If you use something like this, it should at least make debugging simpler. Then substitute the code I've provided with this line:

Application.Workbooks.Open Filename:=ThisWorkbook.Path & "\UNIT" & "\MARINER"  

Declare the variables with your other variables. I'm understanding your question to be that "Mariner" is the file name. If it's not, you will need to change the fileNPath.

Dim path As String, fileNPath As String

'add these two values above your code
path = ActiveWorkbook.path
fileNPath = path & "\UNIT\MARINER.xlsm"

Application.Workbooks.Open fileName:=fileNPath   'Change this line 

Once you've done this, you can see the values for the file path in debug mode where the version you have won't have a value until the line that isn't working anyway. So this way, you can SEE what is going on before you try to USE it.

note: To have a macro enabled workbook, it must be .xlsm, not .xlsx

Upvotes: 1

Related Questions