how to open a file in a macro?

mike999

New Member
Joined
Jul 1, 2008
Messages
6
<TABLE class=tborder id=post1611117 cellSpacing=0 cellPadding=6 width="100%" align=center border=0><TBODY><TR vAlign=top><TD class=alt1 id=td_post_1611117 style="BORDER-RIGHT: #ffffff 1px solid">If my database program contains the line "Runprogram C:\myfolder\excelprog.xls" it will run excel and automatically open a macro. I want to be able to pass an extra parameter being the file to be opened by using "Runprogram C:\myfolder\excelprog.xls filetouse.csv". How can I achieve this in the macro please.
Thanks,
Mike
<!-- / message --></TD></TR><TR><TD class=alt2 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid">
user_offline.gif
</TD><TD class=alt1 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 0px solid; BORDER-BOTTOM: #ffffff 1px solid" align=right><!-- controls --></TD></TR></TBODY></TABLE>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Welcome to the Board!

So you want excelprog.xls to open "filetouse.csv"?

If you open excelprog.xls and record a macro opening the .csv file, you can add the resulting code to excelprog.xls' Workbook_Open event. When your db code opens it, it will then open the .csv file.

Hope that helps,
 
Upvote 0
Thanks Smitty, however, I want the filename to be variable. So one day I might want to open filetouse.csv and tomorrow it might be filetouse2.csv. I'd like to pass the name in the command line from the DB.
Cheers,
Mike
 
Upvote 0
I'm working with Powerflex. I use the command "Runprogram" which is effectively the same as running a program from the DOS prompt. So if excel can handle DOS prompt commands like:
C:\myfolder\excelprog.xls variableprogramname
using the macro to read in the program name from the command line that would be perfect.
Thanks again for your efforts,
Mike
 
Upvote 0
Store the parameter to pass in something like a TXT file with a common name and location or store in the registry. Excel would contain a method to read the parameter information that it needs from that external storage.
 
Upvote 0
I'm getting ever closer to what I want but not quite there yet. I'm in a multi user environment. Two people might want to call excel with different csv file names at the same time which would defeat this latest approach I believe. I admit I don't know much about excel but I can't believe there isn't a simple command in excel or VB that takes the next "word" from the calling command line.
Cheers,
Mike
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top