Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Copy and Paste with Macro Between sheets

I have a macro that I am using to copy and paste information between
two workbooks. Since the original file is a txt file that I manually
convert to excel, I decided the best way to do this would be to save
the file, that way I coudl bounce back and forth between them. I have
2 other macros recored at the begining of my code but you can ignore
them. Please help.

Sub EnvelopeSR()
Application.Run "'sample report-do not throw-has instructions.xls'!
DeleteNonNumeric_ColB"
Application.Run "'sample report-do not throw-has instructions.xls'!
Delete_Rows"
ActiveWorkbook.SaveAs Filename:="Envelopes_SR.XLS"

Workbooks.Open Filename:="G:\Customer_Service\service reports\SR-
Template.xls"
Worksheets("Envelope Detail").Activate
Windows("Envelopes_SR.XLS").Activate
Range("A1:J15000").Copy
Windows("SR-Template.XLS").Activate
Range("A5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

The paste section fails every time.

Jay

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Copy and Paste with Macro Between sheets

Is this code in a General module or is it in a worksheet module?

Try moving it to a General module and try again.

You could try removing the .selects and .activates:

Option Explicit
Sub testme()

Dim TemplateDetailsWks as worksheet
Dim EnvelopeWks as worksheet

set templateDetailsWks _
= Workbooks.Open(Filename:= _
"G:\Customer_Service\service reports\SR-Template.xls") _
.worksheets("Envelope Detail")

set envelopewks = workbooks("Envelopes_SR.XLS") _
.worksheets("whatsheetnamehere")

templatedetailswks.range("A1:J15000").Copy

envelopewks.range("a5").pasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False

End Sub

But you could use the text file (without saving as a normal xls file) directly.

For instance, if the envelope worksheet is the activesheet when the macro
starts, you could use:

set envelopewks = activesheet

I bet you'll still want to save this data into a normal excel workbook file
later, though.

ps. That sample code is untested and uncompiled--watch for typos!

jlclyde wrote:

I have a macro that I am using to copy and paste information between
two workbooks. Since the original file is a txt file that I manually
convert to excel, I decided the best way to do this would be to save
the file, that way I coudl bounce back and forth between them. I have
2 other macros recored at the begining of my code but you can ignore
them. Please help.

Sub EnvelopeSR()
Application.Run "'sample report-do not throw-has instructions.xls'!
DeleteNonNumeric_ColB"
Application.Run "'sample report-do not throw-has instructions.xls'!
Delete_Rows"
ActiveWorkbook.SaveAs Filename:="Envelopes_SR.XLS"

Workbooks.Open Filename:="G:\Customer_Service\service reports\SR-
Template.xls"
Worksheets("Envelope Detail").Activate
Windows("Envelopes_SR.XLS").Activate
Range("A1:J15000").Copy
Windows("SR-Template.XLS").Activate
Range("A5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

The paste section fails every time.

Jay


--

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
Compare two wk sheets with common data using copy paste macro conejo Excel Worksheet Functions 0 October 8th 07 09:21 AM
copy all and paste values for all sheets in a workbook cass calculator Excel Worksheet Functions 6 June 1st 07 02:58 PM
Copy&paste of several sheets Lorenz Excel Discussion (Misc queries) 1 May 29th 07 10:08 PM
Copy-Paste sheets - error in the dates Aninha Excel Worksheet Functions 1 February 28th 06 04:04 PM
copy from one sheet and paste into other sheets TUNGANA KURMA RAJU Excel Discussion (Misc queries) 3 December 8th 05 02:49 PM


All times are GMT +1. The time now is 07:49 PM.

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"