Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a macro from a new excel file

Status
Not open for further replies.

Stoffel24

Technical User
Apr 4, 2002
121
ZA
Hi
I have a problem with a csv file that I create. A new CSV file is created by an application and this file is opened by Excel (As would happen if you double clicked on the CSV file). What I would like is for a macro to execute at this point which will do some simple formatting such as making the columns wide enough to accomodate the data.

I was thinking:
1) Have a universally accessible macro that is available to all excel files.
2) Put in a setting in Excel to make sure that the columns always automatically widen to accomodate the data.

Any ideas on what the best technique would be.

Thanks very much
 
Well, if it is only you that does this then the easiest way would be to hold the code in your PERSONAL.xls
If you already know about the personal.xls file, I won't bore you with how to create it - if not, post back and I'll give you a sbs for how to do it.

Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Using an excel add-in, you can permanently add a macro which is called by the workbook_open event of the application object. This macro can do one of two things. If there is a way with near 100% certainty you can figure out if the workbook opened was of the type you are looking for (maybe checking it's name property and seeing if it ends in ".csv"), then do what you need to do to perform this check (I suggest writing a seperate function) and then run the commands to auto size the columns. If you cannot determine programattically (sp?) whether the file is of the type you are looking for, then your options are sort of limited. you can have a dialog box come up each time asking if you want to autofit the columns, but I think this would get fairly annoying.

-Venkman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top