Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default running a macro saved as a string

I have an Access app that manipulates a spreadsheet. The spreadsheet
can be in one of several pre-defined formats. For each, i have recorded
in Excel a macro that performs the necessary re-formatting. I have
stored these as strings in a table. I want to:
1) based on user choice, create a spreadsheet in one of the possible
formats,
2) open it and then play the appropriate macro

My VBA code (in Access) looks like this:

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open( ... Name of spreadsheet ... )

Now, if the text of the macro is in a string variable (call it
strMacro), what do i call in the Excel object model to execute it ?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default running a macro saved as a string

Try

Eval(xlApp.PublicSub)

-----Original Message-----
I have an Access app that manipulates a spreadsheet. The

spreadsheet
can be in one of several pre-defined formats. For each,

i have recorded
in Excel a macro that performs the necessary re-

formatting. I have
stored these as strings in a table. I want to:
1) based on user choice, create a spreadsheet in one of

the possible
formats,
2) open it and then play the appropriate macro

My VBA code (in Access) looks like this:

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open( ... Name of

spreadsheet ... )

Now, if the text of the macro is in a string variable

(call it
strMacro), what do i call in the Excel object model to

execute it ?


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Not the issue: running a macro saved as a string

No -- not the issue.
I have the macro as a saved string -- example:

Rows("1:1").Select
Selection.Font.Bold = True

Range("C1").Select
ActiveCell.FormulaR1C1 = "'Status"
Range("D1").Select
ActiveCell.FormulaR1C1 = "'Activity #"

Range("B1,F1,G1,H1,I1,J1,K1,L1").Select
Range("L1").Activate
Selection.HorizontalAlignment = xlRight

This string is stored in a variable in the Access app.
It is NOT in some sub in the spreadsheet.
How do i pass it to Excel for execution?
-=-=-=
KM wrote:

Try

Eval(xlApp.PublicSub)

-----Original Message-----
I have an Access app that manipulates a spreadsheet. The

spreadsheet
can be in one of several pre-defined formats. For each,

i have recorded
in Excel a macro that performs the necessary re-

formatting. I have
stored these as strings in a table. I want to:
1) based on user choice, create a spreadsheet in one of

the possible
formats,
2) open it and then play the appropriate macro

My VBA code (in Access) looks like this:

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open( ... Name of

spreadsheet ... )

Now, if the text of the macro is in a string variable

(call it
strMacro), what do i call in the Excel object model to

execute it ?


.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Not the issue: running a macro saved as a string

http://www.cpearson.com/excel/vbe.htm

--
Regards,
Tom Ogilvy


"jfp" wrote in message
...
No -- not the issue.
I have the macro as a saved string -- example:

Rows("1:1").Select
Selection.Font.Bold = True

Range("C1").Select
ActiveCell.FormulaR1C1 = "'Status"
Range("D1").Select
ActiveCell.FormulaR1C1 = "'Activity #"

Range("B1,F1,G1,H1,I1,J1,K1,L1").Select
Range("L1").Activate
Selection.HorizontalAlignment = xlRight

This string is stored in a variable in the Access app.
It is NOT in some sub in the spreadsheet.
How do i pass it to Excel for execution?
-=-=-=
KM wrote:

Try

Eval(xlApp.PublicSub)

-----Original Message-----
I have an Access app that manipulates a spreadsheet. The

spreadsheet
can be in one of several pre-defined formats. For each,

i have recorded
in Excel a macro that performs the necessary re-

formatting. I have
stored these as strings in a table. I want to:
1) based on user choice, create a spreadsheet in one of

the possible
formats,
2) open it and then play the appropriate macro

My VBA code (in Access) looks like this:

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open( ... Name of

spreadsheet ... )

Now, if the text of the macro is in a string variable

(call it
strMacro), what do i call in the Excel object model to

execute it ?


.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Not the issue: running a macro saved as a string

Tom Ogilvy wrote:

http://www.cpearson.com/excel/vbe.htm


OK -- thanks.
I skimmed through this; i need to create a module in the spreadsheet,
paste the saved macro string into it, and then run the macro.
Is there a shorter/simpler way?
This is a "one-time" macro -- it reformats certain cells / column widths
etc. to make the spreadsheet more legible than that created by Access.
There is no need to save it in the spreadsheet. Seems like the ability
to build a string containing some commands and then execute it directly
would be a nice feature in a language this powerful ...


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Not the issue: running a macro saved as a string

The evaluate command cited earlier is supported in VBscript I believe, but
not VBA. I don't know how robust it is in terms of executing your strings.

Personally, if you already have the commands written out, put them in subs
in Access and use a case statement to execute the appropriate sub.

I suspect the capability doesn't exist because there appeared to be little
need for it.

--
Regards,
Tom Ogilvy

"jfp" wrote in message
...
Tom Ogilvy wrote:

http://www.cpearson.com/excel/vbe.htm


OK -- thanks.
I skimmed through this; i need to create a module in the spreadsheet,
paste the saved macro string into it, and then run the macro.
Is there a shorter/simpler way?
This is a "one-time" macro -- it reformats certain cells / column widths
etc. to make the spreadsheet more legible than that created by Access.
There is no need to save it in the spreadsheet. Seems like the ability
to build a string containing some commands and then execute it directly
would be a nice feature in a language this powerful ...



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable running of SelectionChange macro when in another macro? Tonso Excel Discussion (Misc queries) 6 March 21st 10 06:50 PM
Macro buttons opening saved macro Wasabijim Excel Discussion (Misc queries) 0 April 29th 09 08:39 PM
disable user running macro from Tools Macro Steve Simons Excel Discussion (Misc queries) 4 September 28th 06 06:28 AM
Excel converts 9-digit string to sci. not. when saved as csv epen Excel Discussion (Misc queries) 1 September 20th 06 10:15 PM
Launch Macro in Access via Macro running in Excel??? dgrant Excel Programming 1 September 24th 03 01:38 PM


All times are GMT +1. The time now is 06:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"