View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
John Smith John Smith is offline
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).