1

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

8
  • FWIW, that code appears to work. I just right-clicked Copy as path a macro-enabled workbook from my Documents folder and pasted that into your code then removed .xlsm from the string. Worked fine. Commented Jan 8, 2015 at 7:44
  • 1
    Have you tried to add the extension to the path like "\MARINER\filenam.xlsm"? Commented Jan 8, 2015 at 7:44
  • i got it i omit "\" before the MARINER and add the "\" after the UNIT :D Commented Jan 8, 2015 at 7:47
  • 3
    Just to be clear, you have MARINER.xlsx and MARINER.xlsm in the same folder and you want to open MARINER.xlsm? Commented Jan 8, 2015 at 8:59
  • 1
    Unrelated, but is there a specific reason you are using "\UNIT" & "\MARINER" instead of "\UNIT\MARINER"? Commented Jan 8, 2015 at 9:25

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.