• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

[solved] Opening a file from vba with a button doesn't work

Nightlytic

Member
''' Please ignore I just found out the buttons I was using also had hyperlinks,. Figures you can have both a macro and a hyperlink attached to one button o_O
Works now... sorry


Can someone help me please? My macro fails at the very start, extract below, thing is it works perfectly from the VBA console, but not when mapped to a button within workbook x

Sub ImportFiles()
'Declare this workbook (workbook running the macro) x, export as z and import as y
Dim x As Workbook
Dim y As Workbook
Dim z As Workbook

Set x = ThisWorkbook

'### Open export file, parse first column ###
Set z = Workbooks.Open(x.Sheets("Import Files").Range("K17"))
'Operations
End Sub

The red line is the problem, all I want is to set z as the workbook I open, file path to that is contained in workbook x, sheet import files, in cell K17. This works from the VBA console but not in a button (the file doesn't open) I just don't know what's wrong with it it seems logical and I had this exact same start work in another workbook....
 
Hello
I have tested your code and it is working well for me
I suppose that the path is existing in K17 like that for example
Code:
C:\Users\Future\Desktop\Sample.xlsm

Please put the codes between code tags
Code:
Sub ImportFiles()
    'Declare this workbook (workbook running the macro) x, export as z and import as y
    Dim x As Workbook
    Dim y As Workbook
    Dim z As Workbook

    Set x = ThisWorkbook

    '### Open export file, parse first column ###
    Set z = Workbooks.Open(x.Sheets("Import Files").Range("K17"))
    'Operations
End Sub
 
Back
Top