Is there a way to make Excel ignore certain command line arguments? I am launching via a command similar to:
Excel "C:\Temp\TestingCLAs.xlsx" /e service=http://localhost:61023/api/PortlandDev/2/ReportSource?Order='100146309'^&Line='0010'
The service string gets read by some VBA in the Excel file and is used to update a query. However, when I launch Excel the command line argument interpreter see's two things:
Open "C:\Temp\TestingCLASs.xlsx"
Open service=http://....
I would like the interpreter to ignore the second argument, however I get the following error when opening:
"Sorry, we couldn't find
service=http://localhost:61023/api/PortlandDev/2/ReportSource?Order='100146309'&Line='0010'.xlsx.
Is it possible it was moved, renamed or deleted?
I know this isn't due to the VBA within the excel file because it happens even when testing with a blank excel file.
I found this reference article: https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ and tried to escape the URL with a '^' character but, got the same result.
Also looking at the error above, a .xlsx is tacked on to the end of the second URL above when it wasn't specified in the initial call.
Is there a way to make the command interpreter not try to execute the URL?
Any ideas are very much appreciated. Thanks
Not sure why it works but passing a "/p" switch makes it so that the command interpreter does not try to automatically open the URL. For example, the following can be consumed by my internal VBA without the command interpreter trying to create a new workbook from the URL.
Excel "C:\Temp\Template.xlsm" /e /p http://localhost:61023/api/PortlandDev/2/ReportSource?Order='100142574'&Line='0010'
Related
I have a Solidworks PDM transition that launches a particular Excel sheet that has a Workbook_Open routine that receives a parameter passed in from PDM. That parameter is the %folderpath% of the file being transitioned in PDM. The Excel routines run fine. However, Excel is trying to do too much with the passed in path. After the routine in Excel runs, an Excel dialog is throw as shown here:
Excel is mashing the passed in path with an .xlsx extension (its running a .xlsm file). Here is the command line being executed in PDM "C:\Program Files (x86)\Microsoft Office\Root\Office16\EXCEL.EXE""C:\Users\guy\Desktop\TEST FOLDER RENAME.xlsm" /e/ %FolderPath% where the full folder path is C:\PTI\ECO\General\CR-0023482. Any ideas on why Excel is throwing this message and is there a way to suppress/stop it?
I found the issue and it is subtle. The command line in PDM's transitions action cannot have a space between the called spreadsheet and the passed in parameter. This argument works. "C:\Temp\F-Rename.xlsm"/e/%FolderPath% vs. "C:\Temp\F-Rename.xlsm" /e/%FolderPath%.
Here's my problem:
I want to open an Excel file which serves as a template. This file should be edited and then saved. The name is a variable, so it should always change. I.e. variable A that changes all the time.
With the function [xlsread] I open the template and with the function [xlswrite] I can change it as I like and it works without problems. The problem is I can't save the file separately, that means that after editing the template I only get 1 file back, but I want to keep the template and get an edited file so I can use the template again. I could not find a way to save the edited Excel file.
Please help me
There is a mistake in your thinking. xlsread reads the whole file and keeps it in memory. When you use xlswrite your variables from memory are written to a file, with no link to the file read (as long as you change the file name).
That having said, please note that Matlab recommends to use writetable/writematrix/writecell instead of xlswrite. The same is true for xlsread => readtable/readmatrix/readcell.
I'm sure that there are different ways to phrase this question, but that is the end result that I want to achieve.
So, I have a setup where code is written in C# and added as functions to Excel. It relies on having a specific .tlb file in the Tools->References that can be found in the VBA window.
While I was testing this, the .tlb file (and the rest of them) was on my local drive, but now that the project is working, I need to transfer it to a network drive. The problem is that I can't find any way to change the actual file (or filepath) that is being referenced - it's always looking at my local path.
I've tried a few things:
Followed the steps listed here https://support.microsoft.com/en-us/help/308340/how-to-check-and-remove-incorrect-project-references-in-the-visual-bas
Tried several VBA codes using the .References.Remove expression. This does not actually remove the reference from the list, it only unticks it.
I've tried to remove the file from my local drive (causing an Excel error that a reference has been moved, deleted or renamed - good) and then add a reference from the new location that I want. This resulted in one of two things:
1) If I try to add it manually - nothing happens, the existing reference remains unticked and nothing new is added (that I know of).
2) If I try to do it via .References.AddFromFile "filepath" expression it ticks the reference, if it was unticked (this does not make the external formulas work), or an error that a reference with such a name already exists, if it was ticked.
Recompile on the network drive with the following silly way.
Open the VBA editor
Go into each module
Insert a line (doesn't matter what you write)
Press ENTER
Remove the line that you've inserted
When finished, in the menu click Debug \ Compile
Source: by Andreas Killer
https://answers.microsoft.com/en-us/msoffice/forum/all/ms-excel-error-cannot-run-the-macro-the-macros-may/3f3106b2-ae60-4d21-ac94-67e54e605922
Consider I have the following :
An Excel workbook, which generates a .txt file (through a macro).
An executable file (.exe) which can parse this .txt file.
My objective here is to program the following algorithm :
Get the user to enter his data in the worksheets.
Prepare the .txt file according to what the user entered.
Pass the newly created .txt file to the external program (.exe).
Now, the first two steps work perfectly, I can generate the proper .txt file. The problem comes when I need to pass it to the external executable. Here's what's tried and observed :
Calling Shell() with : "C:\path\to\program.exe" "C:\path\to\file.txt" (EDIT : as a single string) ; simple enough, yet this does not work : the external .exe doesn't like being given a path. I have also tried entering the command directly into Windows' Execute utility : same. It seems like giving the program a path to the .txt isn't enough.
Dragging the .txt file onto the program's .exe works! The external executable does its work correctly. Here, it is as if I had passed the "file" to the program, not just its path. As a UNIX user, this sound like quite a non-sense to me (without a notion of stream or pipe), so maybe I'm missing something here...
Now, here's my question. When dragging-n-dropping a file onto an executable, how does Windows "translate" it ? Obviously, it does not translate it to "pass the file's path as the program's first parameter". How can I pass the .txt file to the executable program, without just passing its path like I did with my first Shell() call ?
A few other notes :
I am using Microsoft Office Excel 2010 on Windows 7. I'm already dying from it, thanks for your concern.
This external .exe I'm talking about cannot be modified and recompiled (which would be awesome), that's the tricky thing. I have to use it as it is, whatever happens.
Using Shell() is not a problem, if you give me the proper command/fix. I have also tried calling Run on a VBA.CreateObject("WScript.Shell"), same result.
Now, here's my question. When dragging-n-dropping a file onto an
executable, how does Windows "translate" it ? Obviously, it does not
translate it to "pass the file's path as the program's first
parameter".
It does exactly that. Create a batch file:
#echo off
echo You passed parameter: %1
pause
Save it as test.bat
Browse to it in file explorer, and drag/drop something onto it:
Previous comments:
Looks like you have to send the path and filename as one parameter, e.g.:
Shell("C:\path\to\program.exe C:\path\to\file.txt")
or if the paths have spaces in them, maybe:
Shell("""C:\path\to\program.exe"" ""C:\path\to\file.txt""")
http://social.msdn.microsoft.com/Forums/en-US/a3a3d1a7-5c9a-4c91-ab96-41d367eac2fb/using-shell-function-in-vba-how-do-i-pass-a-parameter?forum=accessdev
Issue : I need to open an excel document, run the macro, save the document in a sepcific name (XXXX_YYYYMMDD), close excel document.
Solution 1:
I think i can use a .bat file to open the excel, run the macro , save and rename the file.
Issue of solution 1:
a) I do not no how to pass the path of the file as a parameter.
b) I do know how write the process in script language for the .bat
Solution 2:
I think i can use a .bat file to open the excel, and create a macro that once excel open it run and rename the excel and close it.
Issue of solution 1:
a) I do not no how to pass the path of the file as a parameter.
PS: Totally new with .bat coding
Other proposal are most welcome
Thank you very much for your help
To answer your first question, you can pass the filename as a parameter by using
batfile.bat yourexcelfile.xls
and access it from the batch file using %1.
However, I don't know how to do the other macro things, but if you find out you can use this to put it together! :)
I am not sure if this is possible with BAt-Files, but I think a powersheel script could do it....
If this is not an option you might try to add the macro to the startup of the file - so it gets run when the file is opened...
You can try with a hybrid bat/jscript file:
rem ("open macro")/*
#echo off
call cscript //nologo //E:jscript excelfile.xsls
goto :eof
*/
var objExcel = new ActiveXObject ("Excel.Application");
objExcel.Application.Run(""+WScript.Arguments.Item(0)+!mymacro");
rem (){}
If the macro is embeded in a sheet you'll need to create a sheet object and access trough it.