Link to home
Start Free TrialLog in
Avatar of Roger
RogerFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel vba open file using default application in Windows 10 64 bit laptop, via ShellExcecute?

With excel 2016, I browse for my doc file (eg .docx, pdf, etc) or graphic file (eg .jpg, gif, pttx, etc) via Application.FileDialog(msoFileDialogFilePicker)
and wish to open it with my pc's default application.

This showed me a ShellExcecute API procedure
https://stackoverflow.com/questions/18921168/how-can-excel-vba-open-file-using-default-application

for this is have a reference for a 32-bit machine:
https://support.microsoft.com/en-us/help/170918/how-to-use-shellexecute-to-launch-associated-file-32-bit

but my pc is 64-bit.

Please can you point me to the appropriate solution. (I am not 'agile' with API scripting, more 'cut and paste')
Thanks!
Kelvin
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roger

ASKER

@Rgonzo1971
Instant response - thanks.
      Always encouraged when I get your comments.
       I find I cant follow this up practically for 24 hours.
I give notice that I am actively engaged with your comment.
Kelvin
Avatar of Roger

ASKER

Hi @Rgonzo
I dont understand the directions in:
https://support.microsoft.com/en-us/help/170918/how-to-use-shellexecute-to-launch-associated-file-32-bit

'Step-by-Step Example

The following example demonstrates how to start an application or load a document into its associated application. The Windows API ShellExecute() function is different from the Visual Basic Shell() function in that you can pass the ShellExecute() function the name of a document and it will launch the associated application, and then pass the filename to the application.

Start a New project in Visual Basic. Form1 is created by default.
Add the following code to the General Declarations section of Form1:  '

--------------------------------------------
I continue:
the procedure starts from    Private Sub Form_Click()   which looks like a click event for a userForm.
--- does that mean that 'Form1' at the end of step-by-step is in fact UserForm1?

Thinking 'YES' I created UserForm1 and put the API code in the UserForm code sheet.

I ran Userform1 from a standard code module: UserForm1.Show   ... which it did, but nothing else happened when I clicked the UserForm.

Can you comment further?
I attach my current file

Thanks! Kelvin
1.-Shell-API-open-file-with-default.xlsm
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roger

ASKER

Thank you, @Norie

I'm using Application.FileDialog(msoFileDialogFilePicker) to select one file at a time with
Debug.print "File path =  "; fDialog.SelectedItems(1)

So I would adapt your code above so that:
 r = StartDoc(fDialog.SelectedItems(1))

I'll test it out asap,
Thanks

Kelvin
Avatar of Roger

ASKER

Problem solved; files opening from file path alone.
Many thanks
Kelvin