ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   ActiveSheet.Paste - Error help? (https://www.excelbanter.com/excel-discussion-misc-queries/119386-activesheet-paste-error-help.html)

dk_

ActiveSheet.Paste - Error help?
 
This short macro below, gets stopped with an error in the last line
which reads 'ActiveSheet.Paste', if the referenced workbook,
(test1.xls), is already open when the macro is run.

This macro runs without errors on both the Windows Excel97 and the Mac
Excel98 platforms when the referenced workbook 'test1.xls", is not open
at the time that this macro is run.

(This is the beginning of a longer macro.)

How can this procedure be fixed to make it so the macro can run even if
the "test1.xls" workbook is already open?

This macro is started while viewing an active workbook with downloaded
quotes.


.....Macro starts below here....

Sub TEST_Quote_Copier()
Application.ScreenUpdating = False
Range("A1:I120").Copy

mydir = ActiveWorkbook.Path
Workbooks.Open FileName:=mydir & Application.PathSeparator &
"test1.xls"

Sheets("xyzQuotes").Activate
Range("A10").Select
ActiveSheet.Paste
End Sub


.... am enjoying the learning curve.

Thanks for all the help.

-Dennis

Walid M. Bahgat

ActiveSheet.Paste - Error help?
 
change it to be this procedure

Sub TEST_Quote_Copier()
Dim x As Workbook
Dim mydir As String
Application.ScreenUpdating = False
Range("A1:I120").Copy

mydir = ActiveWorkbook.Path

For Each x In Workbooks
If x.Name = "test1.xls" Then
x.Activate
Sheets("xyzQuotes").Activate
Range("A10").Select
ActiveSheet.Paste
Exit Sub
End If

Next
Workbooks.Open Filename:=mydir & Application.PathSeparator & "test1.xls"
Sheets("xyzQuotes").Activate
Range("A10").Select
ActiveSheet.Paste
End Sub

"dk_" wrote:

This short macro below, gets stopped with an error in the last line
which reads 'ActiveSheet.Paste', if the referenced workbook,
(test1.xls), is already open when the macro is run.

This macro runs without errors on both the Windows Excel97 and the Mac
Excel98 platforms when the referenced workbook 'test1.xls", is not open
at the time that this macro is run.

(This is the beginning of a longer macro.)

How can this procedure be fixed to make it so the macro can run even if
the "test1.xls" workbook is already open?

This macro is started while viewing an active workbook with downloaded
quotes.


.....Macro starts below here....

Sub TEST_Quote_Copier()
Application.ScreenUpdating = False
Range("A1:I120").Copy

mydir = ActiveWorkbook.Path
Workbooks.Open FileName:=mydir & Application.PathSeparator &
"test1.xls"

Sheets("xyzQuotes").Activate
Range("A10").Select
ActiveSheet.Paste
End Sub


.... am enjoying the learning curve.

Thanks for all the help.

-Dennis


Don Guillett

ActiveSheet.Paste - Error help?
 

Try this which does not need to open the destination wb.
Sub copytoopenwbfromactivewb()' ONE line
Range("c5:c8").Copy Workbooks("yourfile.xls").Sheets("sheet1").Range(" a1")
End Sub
or this for ease of reading with continuation _ character
Sub copytoopenwbfromactivewb()' split line
Range("c5:c8").Copy _
Workbooks("yourfile.xls").Sheets("sheet1").Range(" a1")
End Sub

--
Don Guillett
SalesAid Software

"dk_" wrote in message
...
This short macro below, gets stopped with an error in the last line
which reads 'ActiveSheet.Paste', if the referenced workbook,
(test1.xls), is already open when the macro is run.

This macro runs without errors on both the Windows Excel97 and the Mac
Excel98 platforms when the referenced workbook 'test1.xls", is not open
at the time that this macro is run.

(This is the beginning of a longer macro.)

How can this procedure be fixed to make it so the macro can run even if
the "test1.xls" workbook is already open?

This macro is started while viewing an active workbook with downloaded
quotes.


....Macro starts below here....

Sub TEST_Quote_Copier()
Application.ScreenUpdating = False
Range("A1:I120").Copy

mydir = ActiveWorkbook.Path
Workbooks.Open FileName:=mydir & Application.PathSeparator &
"test1.xls"

Sheets("xyzQuotes").Activate
Range("A10").Select
ActiveSheet.Paste
End Sub


... am enjoying the learning curve.

Thanks for all the help.

-Dennis




dk_

ActiveSheet.Paste - Error help?
 
Walid,

Your code below, gets stopped at the same place as my code below, when
my 'test1.xls' file is open.

It does run the same as my code below when my test1 file is closed.

Thanks.

-Dennis



In article ,
Walid M. Bahgat wrote:

change it to be this procedure

Sub TEST_Quote_Copier()
Dim x As Workbook
Dim mydir As String
Application.ScreenUpdating = False
Range("A1:I120").Copy

mydir = ActiveWorkbook.Path

For Each x In Workbooks
If x.Name = "test1.xls" Then
x.Activate
Sheets("xyzQuotes").Activate
Range("A10").Select
ActiveSheet.Paste
Exit Sub
End If

Next
Workbooks.Open Filename:=mydir & Application.PathSeparator & "test1.xls"
Sheets("xyzQuotes").Activate
Range("A10").Select
ActiveSheet.Paste
End Sub

"dk_" wrote:

This short macro below, gets stopped with an error in the last line
which reads 'ActiveSheet.Paste', if the referenced workbook,
(test1.xls), is already open when the macro is run.

This macro runs without errors on both the Windows Excel97 and the Mac
Excel98 platforms when the referenced workbook 'test1.xls", is not open
at the time that this macro is run.

(This is the beginning of a longer macro.)

How can this procedure be fixed to make it so the macro can run even if
the "test1.xls" workbook is already open?

This macro is started while viewing an active workbook with downloaded
quotes.


.....Macro starts below here....

Sub TEST_Quote_Copier()
Application.ScreenUpdating = False
Range("A1:I120").Copy

mydir = ActiveWorkbook.Path
Workbooks.Open FileName:=mydir & Application.PathSeparator &
"test1.xls"

Sheets("xyzQuotes").Activate
Range("A10").Select
ActiveSheet.Paste
End Sub


.... am enjoying the learning curve.

Thanks for all the help.

-Dennis


dk_

ActiveSheet.Paste - Error help?
 
Don,

Your code works, but ONLY when the file my 'test1.xls' file is already
open.

When my file 'test1.xls' is closed, Excel gets stopped with:

Run-time error '9'
Subscript out of range.

How could I include your example with an 'IF' test, to run your code if
my 'test1.xls' file is open, OR run my code, posted below, if the
'test1.xls' file in NOT open?

Thanks for the instruction.

I will use your example in other types of copying data situations to be
used for files that are already open.

-Dennis



In article ,
"Don Guillett" wrote:

Try this which does not need to open the destination wb.
Sub copytoopenwbfromactivewb()' ONE line
Range("c5:c8").Copy Workbooks("yourfile.xls").Sheets("sheet1").Range(" a1")
End Sub
or this for ease of reading with continuation _ character
Sub copytoopenwbfromactivewb()' split line
Range("c5:c8").Copy _
Workbooks("yourfile.xls").Sheets("sheet1").Range(" a1")
End Sub

--
Don Guillett
SalesAid Software

"dk_" wrote in message
...
This short macro below, gets stopped with an error in the last line
which reads 'ActiveSheet.Paste', if the referenced workbook,
(test1.xls), is already open when the macro is run.

This macro runs without errors on both the Windows Excel97 and the Mac
Excel98 platforms when the referenced workbook 'test1.xls", is not open
at the time that this macro is run.

(This is the beginning of a longer macro.)

How can this procedure be fixed to make it so the macro can run even if
the "test1.xls" workbook is already open?

This macro is started while viewing an active workbook with downloaded
quotes.


....Macro starts below here....

Sub TEST_Quote_Copier()
Application.ScreenUpdating = False
Range("A1:I120").Copy

mydir = ActiveWorkbook.Path
Workbooks.Open FileName:=mydir & Application.PathSeparator &
"test1.xls"

Sheets("xyzQuotes").Activate
Range("A10").Select
ActiveSheet.Paste
End Sub


... am enjoying the learning curve.

Thanks for all the help.

-Dennis





All times are GMT +1. The time now is 08:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com