#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 76
Default macro help

I have a macro for a report and I want to add a worksheet to the macro. My
question is I already have it typed in an excel worksheet. Is there a way to
copy it in the macro without having to re type it to add it to my existing
macro?
Donna
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default macro help

You want to add a worksheet from an existing workbook?

If that existing workbook contains a single sheet:

Dim Sh as object
set sh = sheets.add(type:="c:\pathtothatfile.xls")

Actually, this will add all the sheets in that workbook.

If you wanted to pick out a single sheet, you could use something like:

dim wkbk as workbook
Dim wks as worksheet
dim wkbkName as string
dim wksName as string
dim ActWkbk as workbook

set actwkbk = activeworkbook 'the recipient workbook

wkbkname = "C:\pathtothatfile.xls"
wksname = "somesheetnamehere"

set wkbk = workbooks.open(filename:=wkbkname, readonly:=true)
set wks = wkbk.worksheets(wksname)

wks.copy _
after:=actwkbk.sheets(actwkbk.sheets.count)

wkbk.close savechanges:=false

==========

Untested, uncompiled. Watch for typos.

Donna wrote:

I have a macro for a report and I want to add a worksheet to the macro. My
question is I already have it typed in an excel worksheet. Is there a way to
copy it in the macro without having to re type it to add it to my existing
macro?
Donna


--

Dave Peterson
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 recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 1 February 5th 07 09:31 PM
My excel macro recorder no longer shows up when recording macro jack Excel Discussion (Misc queries) 3 February 5th 07 08:22 PM


All times are GMT +1. The time now is 05:26 PM.

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"