Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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
![]() |
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
HOW DO I SUM TWO CELLS FROM ONE WORKBOOK TO ANOTHER WORKBOOK? | Excel Worksheet Functions | |||
select workbook macro | Excel Discussion (Misc queries) | |||
import select data from another workbook | Excel Worksheet Functions | |||
Unprotect Workbook | Excel Discussion (Misc queries) | |||
Stubborn toolbars in Excel | Excel Discussion (Misc queries) |