I have been attempting various methods of opening a shortcut *.pdf file using command prompt via vba but have had no success yet directly from vba.
If I enter the following in cmd.exe it opens fine:
start "" /max "G:\All Production Drawings\All Production Drawings\Production Drawings\Electronic job card drawing shortcuts\920002300-1.pdf - Shortcut"
I tried the replicating this line of code in vba and had all sorts of problems with the file not either being found or various other errors so I decided to try a different method.
Shell "G:\All Production Drawings\All Production Drawings\Production Drawings\Electronic job card drawing shortcuts\920002300-1.pdf - Shortcut" - this says the file is not found. It is definetly there!
The code below runs with no errors but nothing comes up at all:
Sub opendrawing()
Dim fso As Object
Dim MyFile As String
Set fso = CreateObject("Shell.Application")
MyFile = "G:\All Production Drawings\All Production Drawings\Production Drawings\Electronic job card drawing shortcuts\920002300-1.pdf - Shortcut"
fso.Open (MyFile)
End Sub
If I use either variation of code to open the file directly it works fine but not when I try and open the shortcut. I've been looking about for a while on this one and feel it isn't possible for some reason or another.
Does anyone have any idea on this one please?
Thank you :)
I am playing around with the basics of VBS and have a very simple Visual Basic script which executes a file using shell.
I am using Excel under Windows 10.
Sub Whatever()
Dim Example_One As String
Example_One = "C:\Users\IEUser\python-3.8.0.exe"
Shell Example_One, vbNormalFocus
End Sub
The weird thing is that some files will run (e.g. Python as above) while others e.g. VLC, WinRAR give the error: Run time error 5: Invalid procedure call or argument.
I simply cannot figure out why some .exe files will run and others will not. I thought it might be something to do with how the installation works but ChromeSetup.exe works while VLC.exe does not (even though they both ask "Do you want this app to make changes to your device?" (Python has it's own installer). Double-clicking all files in Windows Explorer runs them as normal (they don't ask for any special rights).
Hoping someone here has a suggestion. I'm a network engineer, who has done a fair amount of programming/scripting over the years, but I'm not a programmer.
My current problem is, I have created a form in Excel to collect data for a particular type of install. I have also used the data entered into the form to create configurations for various network devices involved in this install. These configs are simple text which you can copy and paste, into a telnet or ssh session.
I would like to have a way to click a button in my excel form and push the config to the device automatically, so the user doesn't have to copy and paste it to the device. The sheet already includes a few buttons tied to VBScript macros which perform various functions, including dumping the configs to files. However, as VBScript lacks a native way to open a session (telnet) to a device to send/receive text, I am looking for a way to use a PowerShell script to push the configs.
I have already written a PowerShell Script to push a file containing a text config to a device via telnet, and capture any response to a log file, but I can't find a way to include the PowerShell script as a macro in Excel like you can with a VBScript in MS Visual Basic for Applications.
I've trying to avoid having to create a .MSI or .zip bundle that would include the Excel file and a PowerShell script (or writing something in a compiled .exe). The end goal of this is to have a tool that anyone with Excel running on Windows can fill in, and click a few buttons to send the configurations (text) to a device via telnet, without installing anything on their PC. This tool would be for other network engineers who know far less than me (not that I know much) about scripting or Excel.
Sub RunAndGetCmd()
strCommand = "Powershell -File ""C:\path\to\My PS File.ps1"""
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec(strCommand)
strOutput = WshShellExec.StdOut.ReadAll
Msgbox strOutput
End Sub
OK, so far I've uninstalled & re installed Office-2010 3 to 4 times, done hours of research for 3 days with no success. I started getting this error either from Vbscript or Excel VBA, performing the same command that has worked for months. I am not sure what I may have changed, I don't recall changing anything that could cause it but I nailed it down to the ReadOnly:=True parameter. I think something may be wrong with the registry... but re-installing should fix it right? It didn't...
Anyways, very simple command that I recorded on Excel 2010. This command WORKS FINE and the file opens:
Sub Macro1()
Workbooks.Open Filename:="C:\temp\file_9928_131101.xlsx"
End Sub
But when I add the ReadOnly:=True parameter, it does NOT WORK:
Sub Macro1()
Workbooks.Open Filename:="C:\temp\file_9928_131101.xlsx", ReadOnly:=True
End Sub
This is the returned error Run-time error '1004' Method 'Open' of object 'Workbooks' failed:
When I click Debug, the error is at the only line of code.
The file is corrupted. Resave it with another name and change the name in the function. Try that it works and after that rename the file as you want to call it.
It worked for me and I had a corrupted file. The read only shouldn't be a problem.
Putting an answer here for others like myself who have this issue and the normal solutions don't work.
Another potential cause of this is corrupted temporary files. I think it may only apply if the file you are trying to open is on a network drive or other remote host.
Anyway, try wiping your temp folder (as in the one you get to if you type %temp% into Windows Explorer) then restarting the computer.
I have had the same issue with an Access file stored in a local OneDrive folder, referencing an Excel file stored in the same local OneDrive folder. The solution was to move all files into a "static" (i.e., not synchronized, not OneDrive) folder.
Thought that this specific case/application might help someone.
I realise this is late but if you want to open & repair a corrupted workbook automatically use:
Set oWB = Workbooks.Open(Filename:="C:\my\file\path.xlsx", CorruptLoad:=XlCorruptLoad.xlRepairFile)
If you are downloading the file from some external source (eg- email), just open the file directly from the email and then save the file. Try opening the file in macro ...hope it works...it worked for me....:)
I had a rogue excel process that was running in the background. When I killed it from the task manager the code worked. I hope this helps.
I was too, going crazy with Workbook.Open function, getting the weird Open fail error for no obvious reason. My code also did some some copy-pasting after Open function, which seemed to trigger it.
Eventually I found out that turning ScreenUpdating OFF seemed to cause this - keeping ScreenUpdating ON, made things click for me (maybe someone finds this helpful in the future). I'm one of those who tends to switch ScreenUpdating off for all code whenever possible.
Application.ScreenUpdating = False
I know I'm answering late on this, but I resolved a similar issue (same error but running excel from a .Net app) by making sure VBA was installed correctly on the target machine.
Control Panel->Programs and Features->Uninstall a Program... find your Office install, Right-click and select "change" ->Add Remove Features->Office Shared Features->Visual Basic for Applications->Run From My Computer
This did it for me.
I have the following situation:
There is a Excel workbook saved on another computer on my network. I need to execute the file on that computer, because it is connected with a Big Screen to show some data. I was trying to automate the execution of the workbook but all that I can get is to make it run on MY computer, and I need it to run on THAT computer
The relevant part of the vbs code that I am using is the following:
Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
Set objXLWorkbook = objXL.Workbooks.Open(path)
I know that this method can only open Workbooks on my computer. Anyone knows how to make it run Excel on another computer?
You cannot - out of the box - run programs or scripts on remote computers. Otherwise, it would be even less difficult than it is today to install a virus remotely. Your vbs could simply install and activate a virus instead of an excel file.
Nonetheless its quite a common thing that one wants to do every now and again (the remote task, not the virus - especially administrators love to scare users by remotely opening some funny stuff).
Have a look at an article from Bill Stewart where he explains how to use Powershell to accomplish your task.
The required setup on the remote computer still needs to be done once.