#1   Report Post  
Nigel
 
Posts: n/a
Default workbook select

Hi,
can anyone help me with a macro to select a specific workbook that is
already open? The book is called "1234" quotes & orders
( this can be called "any number" quotes and orders
during my procedure, the book is switched to another book and fills data
from the first book. When the procedure is complete, i need to select the
original book from where i started from ("1234" quotes & orders) i might have
more books open with the same quotes and orders name but diferent "1234" at
the same time. so i would need it to do the following:

get name of active workbook as procedure starts, run prcedure and re-select
book.
the number"1234" can be found on the 2nd book at range("A1") if this helps.
i have tried alot but cannot get it to work.

regards,

nigel
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Option explicit
sub testme01()
dim curWkbk as workbook

set curwkbk = activeworkbook
'do your stuff

curwkbk.activate
end sub

By using an object variable that represents the workbook, you don't have to rely
on the name.

Nigel wrote:

Hi,
can anyone help me with a macro to select a specific workbook that is
already open? The book is called "1234" quotes & orders
( this can be called "any number" quotes and orders
during my procedure, the book is switched to another book and fills data
from the first book. When the procedure is complete, i need to select the
original book from where i started from ("1234" quotes & orders) i might have
more books open with the same quotes and orders name but diferent "1234" at
the same time. so i would need it to do the following:

get name of active workbook as procedure starts, run prcedure and re-select
book.
the number"1234" can be found on the 2nd book at range("A1") if this helps.
i have tried alot but cannot get it to work.

regards,

nigel


--

Dave Peterson
  #3   Report Post  
Nigel
 
Posts: n/a
Default

Hi,
Can this still work if it starts with one macro in one book, but needs
another macro in another book to get it back to the starting book?

Nigel


"Dave Peterson" wrote:

Option explicit
sub testme01()
dim curWkbk as workbook

set curwkbk = activeworkbook
'do your stuff

curwkbk.activate
end sub

By using an object variable that represents the workbook, you don't have to rely
on the name.

Nigel wrote:

Hi,
can anyone help me with a macro to select a specific workbook that is
already open? The book is called "1234" quotes & orders
( this can be called "any number" quotes and orders
during my procedure, the book is switched to another book and fills data
from the first book. When the procedure is complete, i need to select the
original book from where i started from ("1234" quotes & orders) i might have
more books open with the same quotes and orders name but diferent "1234" at
the same time. so i would need it to do the following:

get name of active workbook as procedure starts, run prcedure and re-select
book.
the number"1234" can be found on the 2nd book at range("A1") if this helps.
i have tried alot but cannot get it to work.

regards,

nigel


--

Dave Peterson

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

No.

I was going to suggest that you run a function in the workbook to return the
name, but you'd have to know the name of the workbook to get to that function.
So that won't work.

How about saving the name in a text file and read that text file to get back.

Option Explicit
Sub WriteItOut()

Dim myFileName As String
Dim FileNum As Long
myFileName = Environ("temp") & "\someuniquenamegoeshere.txt"

FileNum = FreeFile
On Error Resume Next
Kill myFileName
On Error GoTo 0

Close #FileNum
Open myFileName For Output As FileNum
Print #FileNum, ActiveWorkbook.Name
Close #FileNum

End Sub


And to get it back...

Option Explicit
Sub ReadItBack()

Dim myFileName As String
Dim FileNum As Long
Dim myLine As String
Dim testStr As String
Dim wkbk As Workbook

myFileName = Environ("temp") & "\someuniquenamegoeshere.txt"

testStr = ""
On Error Resume Next
testStr = Dir(myFileName)
On Error GoTo 0

If testStr = "" Then
MsgBox "Name wasn't saved correctly!"
Exit Sub
End If

FileNum = FreeFile
Close FileNum
Open myFileName For Input As FileNum
Line Input #FileNum, myLine
Close FileNum

Set wkbk = Nothing
On Error Resume Next
Set wkbk = Workbooks(myLine)
On Error GoTo 0

If wkbk Is Nothing Then
MsgBox myLine & " is no longer open!"
Exit Sub
End If

wkbk.Activate
End Sub



Nigel wrote:

Hi,
Can this still work if it starts with one macro in one book, but needs
another macro in another book to get it back to the starting book?

Nigel

"Dave Peterson" wrote:

Option explicit
sub testme01()
dim curWkbk as workbook

set curwkbk = activeworkbook
'do your stuff

curwkbk.activate
end sub

By using an object variable that represents the workbook, you don't have to rely
on the name.

Nigel wrote:

Hi,
can anyone help me with a macro to select a specific workbook that is
already open? The book is called "1234" quotes & orders
( this can be called "any number" quotes and orders
during my procedure, the book is switched to another book and fills data
from the first book. When the procedure is complete, i need to select the
original book from where i started from ("1234" quotes & orders) i might have
more books open with the same quotes and orders name but diferent "1234" at
the same time. so i would need it to do the following:

get name of active workbook as procedure starts, run prcedure and re-select
book.
the number"1234" can be found on the 2nd book at range("A1") if this helps.
i have tried alot but cannot get it to work.

regards,

nigel


--

Dave Peterson


--

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
HOW DO I SUM TWO CELLS FROM ONE WORKBOOK TO ANOTHER WORKBOOK? Bill O'Neal Excel Worksheet Functions 8 August 14th 09 11:36 PM
select workbook macro Nigel Excel Discussion (Misc queries) 3 May 16th 05 01:45 PM
import select data from another workbook schoeller Excel Worksheet Functions 0 March 31st 05 03:13 AM
Unprotect Workbook Kent Excel Discussion (Misc queries) 1 February 4th 05 01:07 AM
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 02:02 PM


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