windows 8, open a file vba Access

The following sample code at: https://msdn.microsoft.com/en-us/library/office/gg278437(v=office.15).aspx
doesn't work. I guess this code seems belong to Windows 7.
' Specifying 1 as the second argument opens the application in 
' normal size and gives it the focus.
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)    ' Run Calculator.

Open in new window


I know this is expected to open the calculator. Probably it opens in Windows 7 environment but when I tried with windows 8, it didn't work. So far I have come to this conclusion that there have been some changes thus it doesn't open in windows 8.

Question: Having a file full-path, how can I open a file from Access using VBA?
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>Having a file full-path, how can I open a file from Access using VBA?

it's the same, using Shell function.
0
John TsioumprisSoftware & Systems EngineerCommented:
It seems that this has to do with UAC...try to run your application as administrator or disable UAC
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
in Windows 10, the following code works. Could you give your shell version for me to try?
Set excel_app = New Excel.Application
    Set excel_wb = excel_app.workbooks.Open(Me!cboFolder.Column(1) & "\" & str_File, 0)
    excel_app.Visible = True

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try:

Shell Application.Path & "\EXCEL.exe """ & Me!cboFolder.Column(1) & "\" & str_File & """", vbNormalFocus

Open in new window

or use ShellExecute API:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
                    ByVal hwnd As Long, _
                    ByVal lpOperation As String, _
                    ByVal lpFile As String, _
                    ByVal lpParameters As String, _
                    ByVal lpDirectory As String, _
                    ByVal nShowCmd As Long) As Long
 
Private Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWMINIMIZED As Long = 2

then:

ShellExecute Application.hwnd, "Open", Me!cboFolder.Column(1) & "\" & str_File, vbNullString, 0&, SW_SHOWNORMAL

Open in new window

0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
for your original scripts, you may change to below, and see if that works?

Set excel_app = CreateObject("Excel.Application")
    Set excel_wb = excel_app.workbooks.Open(Me!cboFolder.Column(1) & "\" & str_File, 0)
    excel_app.Visible = True
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Ryan Chong, it works as I have. No need to change it. But, I will try ShellExecute shortly.
0
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
FYI:  in windows 8.x Calc.exe has move to %windir%\system32\calc.exe
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Boyd,
Dim RetVal
RetVal = Shell("%windir%\system32\calc.exe", 1)    ' Run Calculator.

Open in new window

errors. 53 file not found.
0
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
Shell will evaluate the %windir%

You need to use Environ() to get the value for %windir%

use:
Dim RetVal
RetVal = hell( Environ("windir") & "\system32\calc.exe", 1)    ' Run Calculator.

Open in new window

1
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Boyd,

Last one worked. How can I apply a similar code to open:

"C:\Users\Mike\OneDrive\Documents\_MME_Programing\SQl_Server\70-461Book\666054eBook.pdf"

'and:

C:\Users\Mike\OneDrive\Documents\_MME_Programing\SQl_Server\70-461Book\70-461Summary,docx

'and

"C:\Users\Mike\Documents\EE\Excel_1.xlsx"

Open in new window

0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Sub OpenFile()

Application.FollowHyperlink "C:\Users\Mike\OneDrive\Documents\_MME_Programing\SQl_Server\70-461Book\666054eBook.pdf"

'and:

Application.FollowHyperlink "C:\Users\Mike\OneDrive\Documents\_MME_Programing\SQl_Server\70-461Book\70-461Summary.docx"

'and

Application.FollowHyperlink "C:\Users\Mike\Documents\EE\Excel_1.xlsx"
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
any reason to accept TheHiTechCoach's comment #a40949477 as the solution? it seems just repeating the suggestion to use Shell function. furthermore, by using Environ("windir") function will not allowed you to open other files in other directories.

I would suggest to accept eghtebas's comment #a40949527 (0 points)  as the solution
0
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
@Ryan Chong, , I was not repeating the Shell suggestion but offered a solution to why the posted coded  did not work with Windows 8.  Which did answer the original question.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I got some value from Boyd's post and it is much appreciated.
0
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
eghtebas, Thank you. I look forward to assisting you in the future.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
no worries cheers
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I figured out the solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.