Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default possible to save macro with workbook as add-in?

I finished writing a macro. It works well. When I save the macro
as an add-in and then open the add-in, it doesn't work. It
complains about codes like sheet1.Cells(1,2).select. Seems the
workbook was not saved along with the macro.

Is it possible to save the workbook with macro as an add-in?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default possible to save macro with workbook as add-in?

Hi John,

John Smith wrote:
I finished writing a macro. It works well. When I save the macro
as an add-in and then open the add-in, it doesn't work. It
complains about codes like sheet1.Cells(1,2).select. Seems the
workbook was not saved along with the macro.


This is because an Excel add-in has no visible worksheets. So trying to
select one will always result in error. What are you trying to do? Select
something in the active workbook, or get the value from a cell on sheet1 of
the add-in itself? If you want to interact with the user's current active
workbook (which will be different than the add-in), you would use
ActiveSheet or ActiveWorkbook.Worksheets(1) or similar. To interact with
the add-in, you would do like you have done without using the Select method:

Dim sName As String

sName = Sheet1.Cells(1, 2).Value '/ instead of selecting and using
Selection.Value

Is it possible to save the workbook with macro as an add-in?


Yes, but as I said above, the worksheets will not be visible to the end
user. You can still interact with them all you want (if you don't activate
or select anything).

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default possible to save macro with workbook as add-in?

Thanks for the prompt reply. What I would like to do is have the
macro generate a spreadsheet and put formula on the sheet. I tried
something like application.worksheets.add() but that did not work.

Jake Marx wrote:
Hi John,

John Smith wrote:

I finished writing a macro. It works well. When I save the macro
as an add-in and then open the add-in, it doesn't work. It
complains about codes like sheet1.Cells(1,2).select. Seems the
workbook was not saved along with the macro.



This is because an Excel add-in has no visible worksheets. So trying to
select one will always result in error. What are you trying to do? Select
something in the active workbook, or get the value from a cell on sheet1 of
the add-in itself? If you want to interact with the user's current active
workbook (which will be different than the add-in), you would use
ActiveSheet or ActiveWorkbook.Worksheets(1) or similar. To interact with
the add-in, you would do like you have done without using the Select method:

Dim sName As String

sName = Sheet1.Cells(1, 2).Value '/ instead of selecting and using
Selection.Value


Is it possible to save the workbook with macro as an add-in?



Yes, but as I said above, the worksheets will not be visible to the end
user. You can still interact with them all you want (if you don't activate
or select anything).

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default possible to save macro with workbook as add-in?

Hi John,

OK. Since your add-in is hidden, adding worksheets to it wouldn't do you
any good (that is, if you want your end user to see the new worksheet). So,
you probably want to create a new workbook and add formulas to the first
worksheet in that workbook, right? If so, here's how you could do it:

Sub demo()
Dim wb As Workbook

Set wb = Workbooks.Add

With wb.Worksheets(1)
.Cells(1, 1).Value = 2
.Cells(2, 1).Formula = "=A1*2"
End With

Set wb = Nothing
End Sub

This is just a simple example, but hopefully it gets you started in the
right direction.

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]


John Smith wrote:
Thanks for the prompt reply. What I would like to do is have the
macro generate a spreadsheet and put formula on the sheet. I tried
something like application.worksheets.add() but that did not work.

Jake Marx wrote:
Hi John,

John Smith wrote:

I finished writing a macro. It works well. When I save the macro
as an add-in and then open the add-in, it doesn't work. It
complains about codes like sheet1.Cells(1,2).select. Seems the
workbook was not saved along with the macro.



This is because an Excel add-in has no visible worksheets. So
trying to select one will always result in error. What are you
trying to do? Select something in the active workbook, or get the
value from a cell on sheet1 of the add-in itself? If you want to
interact with the user's current active workbook (which will be
different than the add-in), you would use ActiveSheet or
ActiveWorkbook.Worksheets(1) or similar. To interact with the
add-in, you would do like you have done without using the Select
method:

Dim sName As String

sName = Sheet1.Cells(1, 2).Value '/ instead of selecting and
using Selection.Value


Is it possible to save the workbook with macro as an add-in?



Yes, but as I said above, the worksheets will not be visible to the
end user. You can still interact with them all you want (if you
don't activate or select anything).



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
Macro save workbook puiuluipui Excel Discussion (Misc queries) 3 November 13th 09 04:40 PM
Macro to save workbook puiuluipui Excel Discussion (Misc queries) 3 October 7th 09 09:17 PM
Macro to Save just one sheet to new workbook. Guy[_2_] Excel Worksheet Functions 2 January 27th 09 09:32 PM
"Save" macro problem, still prompted to save when closing workbook (?) StargateFanFromWork[_4_] Excel Programming 8 September 13th 06 04:49 PM
Use a Macro to Save a Copy of a Workbook? Joe D[_4_] Excel Programming 3 July 14th 05 03:29 PM


All times are GMT +1. The time now is 01:15 AM.

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

About Us

"It's about Microsoft Excel"