Opening a image file - excel

I am having trouble figuring out the VBA syntax to open a file for MAC OS
Here is my code
Sub OpenFile()
Open (Users/dongougkim/ShareSync/Dan's stuff/Current Services/logo.png)
End Sub
I have also tried
Open ("Users/dongougkim/ShareSync/Dan's stuff/Current Services/logo.png")
Open ("Macintosh HD/Users/dongougkim/ShareSync/Dan's stuff/Current Services/logo.png")
Open ("Macintosh HD:Users:dongougkim:ShareSync:Dan's stuff:Current Services:logo.png")
Please help. Driving me crazay

You need to prefix Users with a slash, otherwise the path is relative.
Try this:-
Sub OpenFile()
Open (/Users/dongougkim/ShareSync/Dan's stuff/Current Services/logo.png)
End Sub

Related

Excel VBA Workbook_Open does not work when Excel is already open

I was trying to automate VBA run with its file opening from command line as below:
cmd.exe /C set MacroName=MyMacro \& EXCEL.EXE C:\\_documents\\Book2.xlsm
The VBA scripts and files are as follows:
Book2.xlsm/Module1
Sub MyMacro()
MsgBox "MyMacro is running..."
End Sub
Book2.xlsm/ThisWorkbook
Private Sub Workbook_Open()
Dim strMacroName As String
strMacroName = CreateObject("WScript.Shell").Environment("process").Item("MacroName")
If strMacroName <> "" Then Run strMacroName
End Sub
Now, the above cmd command does work, expectedly notifies me with the MsgBox, when Excel is not open. But it does not work when Excel is already being open with other project/file(s).
How can I make this work?
The problem was that when you launch an Excel file in the already open Excel instance passing environment variables through cmd.exe or command line does not work correctly for some reason, rather than as a VBA-side problem.

Vba Shell call works with some programs but does not work with others

Shell call works with some programs that I have but does not work with others. I am putting the most basic call here for opening an exe without any further commands
Shell "C:\Program Files\qBittorrent\qbittorrent.exe", 1 'works
Shell "C:\Program Files\AmiBroker\Broker.exe", 1 'works
Shell "C:\Program Files\CTrading\QuantShare\QuantShare.exe", 1 'Run-time error '5': Invalid procedure call or argument
Shell "C:\Program Files (x86)\Equis\MetaStock\MsWin.exe", 1 'same error
I am on the verge of giving up unless I meet a savior here!!
System: Windows 10 Pro Version 1909 OS Build 18363.476
Microsoft Excel 2013 64-bit
A bit of an ugly fix, but it might help:
Shell "cmd /c ""C:\Program Files\CTrading\QuantShare\QuantShare.exe""", 1
I don't have any of the programs you are having problems with, so it is a bit of a guess. If this doesn't help, the next step is cmd /c start ...
Finally, i could use ShellExecute as follows:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A2000")) Is Nothing Then
Set objShell = CreateObject("Shell.Application")
para = "TaskManager ChangeSymbol newsymbol:" & ActiveCell.Value
objShell.ShellExecute "C:\Program Files\CTrading\QuantShare\QuantShare.exe", para, "", "open", 1
Set objShell = Nothing
Cancel = True
End If
End Sub
Can I make ShellExecute not to open a new instance of the program and rather activate the currently open instance and pass the arguments (similar to Shell call? Also how to make ShellExecute not take focus? I want the focus to stay back in Excel.

How to enter the user path and directly assign to the command prompt

Right now, I need to create a VBA macro wherein I need to open the cmd.exe then, it will ask the user to enter the path of the file they need to open. Then, the path should be put in the command line. As of now, I already open the location of the cmd.exe and added an inputbox function to enter the path. But, I don't know how to put the value of the path in my command line. Sorry if this seems trivial. I am new to VBA coding.
Private Sub CommandButton22_Click()
Call Shell("cmd.exe /S /K" & "perl a.pl c:\temp", vbNormalFocus)
Dim path As String
path = InputBox("Enter a file path", "Title Here")
Open path For Output As #1
Close #1
End Sub
So, for example the user enter the path: C:\Users\aaa\Desktop\Files\
In command prompt, it should look like this:
<C:\Windows\System32>**cd C:\Users\aaa\Desktop\Files**
Is it possible to do that in VBA?
Thank you.

Shell command on Excel with long path name don't work

I have a batch file run.bat in a network folder "L:\Common Data\myfile" and i want to execute it from an Excel's macro.
Googling around I found these sintax:
Call Shell(Environ$("COMSPEC") & " /k L:\Common Data\myfile\run.bat", vbNormalFocus)
but it fails because it reads only "L:\Common".
I tryed many suggestion found on Internet but no one succeeded.
Someone have a solution?
Path names with spaces have to be wrapped in quotes.
Call Shell(Environ$("COMSPEC") & " /k ""L:\Common Data\myfile\run.bat""", vbNormalFocus)

Excel Macro to Open EXE

I am trying to create a macro that will open the file "test.exe" on drive F/. I get "runtime error 5" when running this code below.
Sub MacroTangoMike()
' MacroTangoMike Macro
RetVal = Shell("F:/test.exe", 1)
End Sub
It works fine though if test.exe is on the C/ drive.
Error 5 is access denied. Are you sure you have the execute permission on the EXE on the F: drive?
Also you should probably be using backslashes \ in your paths on Windows rather than /.

Resources