Henk Straten
Henk Straten

Reputation: 1447

AHK script to open an Excel file does not work

I have the following code to open an Excel file:

F11::             


xlApp.Workbooks.Open("C:\Users\User\Dropbox\PROJECTEN\Continue\pi\personal_dashboard.xlsx")            
        xlApp := ""                                 
    return

When I run it however nothing opens. Any though on whether Im missing something?

Upvotes: 1

Views: 3270

Answers (2)

Relax
Relax

Reputation: 10543

Before opening a (new) COM object, you need to create it:

F11::
    xlApp := ComObjCreate("Excel.Application")    ; create a (new) instance of Excel
    xlApp.Visible := true                         ; make Excel visible
    ; xlApp := ComObjActive("Excel.Application")  ; make Excel active   
    xlApp.Workbooks.Open("C:\Users\User\Dropbox\PROJECTEN\Continue\pi\personal_dashboard.xlsx")    
    xlApp := ""   ; clear the variable
return  

See also https://autohotkey.com/board/topic/56987-com-object-reference-autohotkey-v11/page-4#entry381256

Upvotes: 3

HaveSpacesuit
HaveSpacesuit

Reputation: 3994

You can open a file simply by doing

run "C:\Users\User\Dropbox\PROJECTEN\Continue\pi\personal_dashboard.xlsx"

It would be the same as typing "C:\users...\personal_dashboard.xlsx" into the run dialog. As long as you have Excel as the default program to open .xlsx files, then it should open without problems.

Upvotes: 2

Related Questions