Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Name Active Workbook

I am trying to create a simple copy/paste macro from one workbook with many
tabs to another with many tabs. The process is: a user opens an always
different named workbook runs macro from a menu. The macro then has the user
select the second workbook manually. The macro will then take data from the
second workbook and paste into first workbook.

How do I rename the first workbook only for the duration of the macro so the
macro knows to go back to that file to paste too? I hope this is clear.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Name Active Workbook

What am I doing wrong?

Sub ITMODELCOPY()

Dim wb1 As Workbook
Set wb1 = ActiveWorkbook

MsgBox "Select the IT Model File"
TEMPLa = Application.GetOpenFilename("Excel (*.xls), *.xls")
TEMPL = Dir(TEMPLa)
TEMPLacik = 0
If ActiveWorkbook Is Nothing Then GoTo ac
ad = ActiveWorkbook.Name
If ad = TEMPL Then TEMPLacik = 1
ActiveWindow.ActivateNext
Do While ActiveWorkbook.Name < ad
If ActiveWorkbook.Name = TEMPL Then TEMPLacik = 1
ActiveWindow.ActivateNext
Loop
ac:
If TEMPLacik = 0 Then Workbooks.Open (TEMPLa)
Workbooks(TEMPL).Activate
Sheets("IT Costing Detail").Select
Range("C112").Select

Workbooks(wb1).Activate

"Ron de Bruin" wrote:

Hi Matthew

You can create a reference to the first workbook before you open the other one

Dim wb1 As Workbook
Set wb1 = ActiveWorkbook

You can use wb1 now in your code to paste

wb1.Sheets("Sheet1").Range ("A1")



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Matthew R" <Matthew wrote in message ...
I am trying to create a simple copy/paste macro from one workbook with many
tabs to another with many tabs. The process is: a user opens an always
different named workbook runs macro from a menu. The macro then has the user
select the second workbook manually. The macro will then take data from the
second workbook and paste into first workbook.

How do I rename the first workbook only for the duration of the macro so the
macro knows to go back to that file to paste too? I hope this is clear.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Name Active Workbook

Hi

You can test if the workbook is open with a function

Sub ITMODELCOPY()

Dim wb1 As Workbook
Dim TEMPLa As Variant
Dim TEMPL As String
Set wb1 = ActiveWorkbook

MsgBox "Select the IT Model File"
TEMPLa = Application.GetOpenFilename("Excel (*.xls), *.xls")
TEMPL = Dir(TEMPLa)
If bIsBookOpen(TEMPL) Then
'do nothing
Else
Workbooks.Open (TEMPLa)
End If

wb1.Activate
End Sub

Function bIsBookOpen(ByRef szBookName As String) As Boolean
' Rob Bovey
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Matthew R" wrote in message ...
What am I doing wrong?

Sub ITMODELCOPY()

Dim wb1 As Workbook
Set wb1 = ActiveWorkbook

MsgBox "Select the IT Model File"
TEMPLa = Application.GetOpenFilename("Excel (*.xls), *.xls")
TEMPL = Dir(TEMPLa)
TEMPLacik = 0
If ActiveWorkbook Is Nothing Then GoTo ac
ad = ActiveWorkbook.Name
If ad = TEMPL Then TEMPLacik = 1
ActiveWindow.ActivateNext
Do While ActiveWorkbook.Name < ad
If ActiveWorkbook.Name = TEMPL Then TEMPLacik = 1
ActiveWindow.ActivateNext
Loop
ac:
If TEMPLacik = 0 Then Workbooks.Open (TEMPLa)
Workbooks(TEMPL).Activate
Sheets("IT Costing Detail").Select
Range("C112").Select

Workbooks(wb1).Activate

"Ron de Bruin" wrote:

Hi Matthew

You can create a reference to the first workbook before you open the other one

Dim wb1 As Workbook
Set wb1 = ActiveWorkbook

You can use wb1 now in your code to paste

wb1.Sheets("Sheet1").Range ("A1")



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Matthew R" <Matthew wrote in message ...
I am trying to create a simple copy/paste macro from one workbook with many
tabs to another with many tabs. The process is: a user opens an always
different named workbook runs macro from a menu. The macro then has the user
select the second workbook manually. The macro will then take data from the
second workbook and paste into first workbook.

How do I rename the first workbook only for the duration of the macro so the
macro knows to go back to that file to paste too? I hope this is clear.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Name Active Workbook

Thanks Ron!...That worked perfectly. Have a nice day!

"Ron de Bruin" wrote:

Hi

You can test if the workbook is open with a function

Sub ITMODELCOPY()

Dim wb1 As Workbook
Dim TEMPLa As Variant
Dim TEMPL As String
Set wb1 = ActiveWorkbook

MsgBox "Select the IT Model File"
TEMPLa = Application.GetOpenFilename("Excel (*.xls), *.xls")
TEMPL = Dir(TEMPLa)
If bIsBookOpen(TEMPL) Then
'do nothing
Else
Workbooks.Open (TEMPLa)
End If

wb1.Activate
End Sub

Function bIsBookOpen(ByRef szBookName As String) As Boolean
' Rob Bovey
On Error Resume Next
bIsBookOpen = Not (Application.Workbooks(szBookName) Is Nothing)
End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Matthew R" wrote in message ...
What am I doing wrong?

Sub ITMODELCOPY()

Dim wb1 As Workbook
Set wb1 = ActiveWorkbook

MsgBox "Select the IT Model File"
TEMPLa = Application.GetOpenFilename("Excel (*.xls), *.xls")
TEMPL = Dir(TEMPLa)
TEMPLacik = 0
If ActiveWorkbook Is Nothing Then GoTo ac
ad = ActiveWorkbook.Name
If ad = TEMPL Then TEMPLacik = 1
ActiveWindow.ActivateNext
Do While ActiveWorkbook.Name < ad
If ActiveWorkbook.Name = TEMPL Then TEMPLacik = 1
ActiveWindow.ActivateNext
Loop
ac:
If TEMPLacik = 0 Then Workbooks.Open (TEMPLa)
Workbooks(TEMPL).Activate
Sheets("IT Costing Detail").Select
Range("C112").Select

Workbooks(wb1).Activate

"Ron de Bruin" wrote:

Hi Matthew

You can create a reference to the first workbook before you open the other one

Dim wb1 As Workbook
Set wb1 = ActiveWorkbook

You can use wb1 now in your code to paste

wb1.Sheets("Sheet1").Range ("A1")



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Matthew R" <Matthew wrote in message ...
I am trying to create a simple copy/paste macro from one workbook with many
tabs to another with many tabs. The process is: a user opens an always
different named workbook runs macro from a menu. The macro then has the user
select the second workbook manually. The macro will then take data from the
second workbook and paste into first workbook.

How do I rename the first workbook only for the duration of the macro so the
macro knows to go back to that file to paste too? I hope this is clear.









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
Closing Hidden Workbook when Active Workbook is Closed SusanK521 Excel Programming 5 September 24th 05 12:27 AM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM
How do I make an open workbook the active workbook Don Guillett[_4_] Excel Programming 0 December 30th 03 04:28 PM
Copy Modules from One workbook to Active Workbook Jim Gifford Excel Programming 1 November 18th 03 12:30 PM
Preventing opening workbook inside active workbook. Serge[_4_] Excel Programming 2 November 4th 03 07:51 PM


All times are GMT +1. The time now is 10:06 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"