Mike Eghtebas
asked on
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.
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?
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.
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?
It seems that this has to do with UAC...try to run your application as administrator or disable UAC
ASKER
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
try:
Shell Application.Path & "\EXCEL.exe """ & Me!cboFolder.Column(1) & "\" & str_File & """", vbNormalFocus
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
for your original scripts, you may change to below, and see if that works?
Set excel_app = CreateObject("Excel.Applic ation")
Set excel_wb = excel_app.workbooks.Open(M e!cboFolde r.Column(1 ) & "\" & str_File, 0)
excel_app.Visible = True
Set excel_app = CreateObject("Excel.Applic
Set excel_wb = excel_app.workbooks.Open(M
excel_app.Visible = True
ASKER
Ryan Chong, it works as I have. No need to change it. But, I will try ShellExecute shortly.
FYI: in windows 8.x Calc.exe has move to %windir%\system32\calc.exe
ASKER
Boyd,
Dim RetVal
RetVal = Shell("%windir%\system32\calc.exe", 1) ' Run Calculator.
errors. 53 file not found.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Boyd,
Last one worked. How can I apply a similar code to open:
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"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
I would suggest to accept eghtebas's comment #a40949527 (0 points) as the solution
@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.
ASKER
I got some value from Boyd's post and it is much appreciated.
eghtebas, Thank you. I look forward to assisting you in the future.
no worries cheers
ASKER
I figured out the solution.
it's the same, using Shell function.