I am writing a macro to perform several actions. In the first action I have one file open and I need to write a code or another macro that will open a second file. The name of the second file will always change. Once the second file is open, I will then continue to the next action. Can you help me with the code? Thank you.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
macro to open a file (Excel 2000)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » macro to open a file (Excel 2000)
- This topic has 39 replies, 6 voices, and was last updated 20 years, 7 months ago.
AuthorTopicWScindypositano
AskWoody LoungerNovember 15, 2004 at 4:01 pm #412275Viewing 3 reply threadsAuthorReplies-
WSsdckapr
AskWoody Lounger -
WScindypositano
AskWoody LoungerNovember 15, 2004 at 5:13 pm #900193The purpose of the overall macro is to copy data from one file (closed) and paste the data into the destination file (open) I need the macro to pause so the user can select the correct file to open. When the file is open, the macro can resume the rest of the actions. The files to open are all identical in layout, etc. Only the numbers are different. Thank you.
-
WScindypositano
AskWoody LoungerNovember 15, 2004 at 5:13 pm #900194The purpose of the overall macro is to copy data from one file (closed) and paste the data into the destination file (open) I need the macro to pause so the user can select the correct file to open. When the file is open, the macro can resume the rest of the actions. The files to open are all identical in layout, etc. Only the numbers are different. Thank you.
-
-
WSsdckapr
AskWoody Lounger -
H. Legare Coleman
AskWoody PlusNovember 15, 2004 at 5:19 pm #900197Is something like this what you are looking for?
Option Explicit Sub OpenTargetFile() Dim vTargetFile As Variant Dim wbkTarget As Workbook vTargetFile = Application.GetOpenFilename("Excel Files (*.xls),*.xls, All Files (*.*),*.*", _ 1, "Select Target File") If vTargetFile = False Then Exit Sub End If Set wbkTarget = Workbooks.Open(vTargetFile) End Sub
-
WScindypositano
AskWoody LoungerNovember 15, 2004 at 5:58 pm #900222When I paste your code inside my macro, the code displays all on one line in red. The error message “Compile Error: Syntax Error” is displayed. Here is my current code. I need to open a file the line above this action. Thank you.
Sub CommandButton1_Click()
‘
‘ Sub Interbranch()
‘
‘ InterbranchCopy Macro
‘ Macro recorded 11/09/2004 by bxwallac
‘
Dim DWB As Workbook
Dim DestinationBook As String
Set CWB = ActiveWorkbook
DestinationBook = Application.GetOpenFilename(“All Excel Files,*.xls”)
Workbooks.Open DestinationBook
Set DWB = ActiveWorkbook
CWB.Activate
Sheets(“Inter-Branch Allocation”).Range(“A1216:BI1251”).Copy DWB.Sheets(“Inter-Branch Allocation”).Range(“A1216”)
Sheets(“Detailed Financials”).Range(“AA82:BT82”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA82”)
Sheets(“Detailed Financials”).Range(“AA95:BT95”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA95”)
Sheets(“Monthly Plan Summary”).Range(“Y29:BR29”).Copy DWB.Sheets(“Monthly Plan Summary”).Range(“Y29”)
DWB.ActivateEnd Sub
-
H. Legare Coleman
AskWoody Plus -
WScindypositano
AskWoody LoungerNovember 15, 2004 at 6:30 pm #900232I did as you said. I now get the message, “Invisible inside procedure”. Here is the code.
Sub Macro5()
‘
‘ Macro5 Macro
‘ Macro recorded 11/15/2004 by consultant
‘
Option ExplicitSub OpenTargetFile()
Dim vTargetFile As Variant
Dim wbkTarget As Workbook
vTargetFile = Application.GetOpenFilename(“Excel Files (*.xls),*.xls, All Files (*.*),*.*”, _
1, “Select Target File”)
If vTargetFile = False Then
Exit Sub
End If
Set wbkTarget = Workbooks.Open(vTargetFile)
End Sub -
H. Legare Coleman
AskWoody PlusNovember 15, 2004 at 7:04 pm #900262I believe that the message should have been “Invalid inside procedure” not Invisible.
You pasted my code inside another procedure. That did two things. First, it put the Option Explicit statement inside your procedure, and the Option Explicit statement must be outside all procedures. Move it outside your procedure. BTW, having this statement will require that all variables be declared with a DIM statement. This can catch all kinds of errors that occur by having such errors as variable names spelled differently.
Second, you put my “Sub OpenTargetFile()” inside your procedure. You can’t have a procedure inside a procedure. Therefore, if you want my code inside your procedure, you will need to remove my “Sub OpenTargetFile()” and the “End Sub” that goes with it.
-
-
WScindypositano
AskWoody LoungerNovember 15, 2004 at 6:30 pm #900233I did as you said. I now get the message, “Invisible inside procedure”. Here is the code.
Sub Macro5()
‘
‘ Macro5 Macro
‘ Macro recorded 11/15/2004 by consultant
‘
Option ExplicitSub OpenTargetFile()
Dim vTargetFile As Variant
Dim wbkTarget As Workbook
vTargetFile = Application.GetOpenFilename(“Excel Files (*.xls),*.xls, All Files (*.*),*.*”, _
1, “Select Target File”)
If vTargetFile = False Then
Exit Sub
End If
Set wbkTarget = Workbooks.Open(vTargetFile)
End Sub
-
-
H. Legare Coleman
AskWoody Plus -
H. Legare Coleman
AskWoody PlusNovember 15, 2004 at 6:21 pm #900228The code below is modified to open a source file. I did not change the code to do anything with that file as I was not clear what you want to do with it.
Sub CommandButton1_Click() ' ' Sub Interbranch() ' ' InterbranchCopy Macro ' Macro recorded 11/09/2004 by bxwallac ' Dim DWB As Workbook Dim CWB As Workbook Dim SWB As Workbook Dim DestinationBook As Variant Dim SourceBook As Variant Set CWB = ActiveWorkbook SourceBook = Application.GetOpenFilename(FileFilter:="All Excel Files,*.xls", Title:="Select Source File") If SourceBook = False Then Exit Sub End If Set SWB = Workbooks.Open(SourceBook) DestinationBook = Application.GetOpenFilename(FileFilter:="All Excel Files,*.xls", Title:="Select Destination File") If DestinationBook = False Then Exit Sub End If Set DWB = Workbooks.Open(DestinationBook) CWB.Activate Sheets("Inter-Branch Allocation").Range("A1216:BI1251").Copy DWB.Sheets("Inter-Branch Allocation").Range("A1216") Sheets("Detailed Financials").Range("AA82:BT82").Copy DWB.Sheets("Detailed Financials").Range("AA82") Sheets("Detailed Financials").Range("AA95:BT95").Copy DWB.Sheets("Detailed Financials").Range("AA95") Sheets("Monthly Plan Summary").Range("Y29:BR29").Copy DWB.Sheets("Monthly Plan Summary").Range("Y29") DWB.Activate End Sub
-
H. Legare Coleman
AskWoody PlusNovember 15, 2004 at 6:21 pm #900229The code below is modified to open a source file. I did not change the code to do anything with that file as I was not clear what you want to do with it.
Sub CommandButton1_Click() ' ' Sub Interbranch() ' ' InterbranchCopy Macro ' Macro recorded 11/09/2004 by bxwallac ' Dim DWB As Workbook Dim CWB As Workbook Dim SWB As Workbook Dim DestinationBook As Variant Dim SourceBook As Variant Set CWB = ActiveWorkbook SourceBook = Application.GetOpenFilename(FileFilter:="All Excel Files,*.xls", Title:="Select Source File") If SourceBook = False Then Exit Sub End If Set SWB = Workbooks.Open(SourceBook) DestinationBook = Application.GetOpenFilename(FileFilter:="All Excel Files,*.xls", Title:="Select Destination File") If DestinationBook = False Then Exit Sub End If Set DWB = Workbooks.Open(DestinationBook) CWB.Activate Sheets("Inter-Branch Allocation").Range("A1216:BI1251").Copy DWB.Sheets("Inter-Branch Allocation").Range("A1216") Sheets("Detailed Financials").Range("AA82:BT82").Copy DWB.Sheets("Detailed Financials").Range("AA82") Sheets("Detailed Financials").Range("AA95:BT95").Copy DWB.Sheets("Detailed Financials").Range("AA95") Sheets("Monthly Plan Summary").Range("Y29:BR29").Copy DWB.Sheets("Monthly Plan Summary").Range("Y29") DWB.Activate End Sub
-
WScindypositano
AskWoody LoungerNovember 15, 2004 at 7:07 pm #900267I believe this will do it. Thank you. Before I begin the action to copy data, in the newly opened file I want to run an ASAP utility called ‘System, Remove VBA Code’. After that I will then unprotect 3 specific sheets. Last step will to be to run the code to copy. Here’s the problem. Before I began writing the code, the utility ASAP was up on the menu. Now it is gone. How can I keep it on the menu so it can be included in the overall macro? Or do you have code that would remove VBA code from the newly opened file? I was going to place this code after the line ‘End If ‘ and before the line ‘Set DWB = Workbooks.Open(DestinationBook)’. Thank you.
-
H. Legare Coleman
AskWoody Plus -
WScindypositano
AskWoody LoungerNovember 15, 2004 at 7:55 pm #900324ASAP Utilities is a free and easy to use Add-In for MS Excel 97/2000/2002/XP/2003. The utility contains over 300 functions to make your work easier, written by Bastien Mensink. I believe I got this info from one of the Woody posts. Anyway, there is a utility called System, Remove all macros/VBA code from current file. In my macro I first need to open the second file (which you helped me with.) Then, I need to remove all macros/VBA code from the newly opened file. with both files open I then run the macro to copy specific data. If I don’t use this utility, do you have code to remove all macros? BTW, You are brilliant! Thank you.
-
WSsdckapr
AskWoody Lounger -
WScindypositano
AskWoody LoungerNovember 15, 2004 at 8:42 pm #900374Ok, this is the code from Chip that is needed to delete the VBA code in the second file. Can you tell me where to paste it in my macro?
Code –
Sub DeleteAllVBA()Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponentsSet VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
Select Case VBComp.Type
Case vbext_ct_StdModule, vbext_ct_MSForm, _
vbext_ct_ClassModule
VBComps.Remove VBComp
Case Else
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Select
Next VBCompEnd Sub
Where do I paste the above code so it will remove the VBA code from the newly opened file before it starts the copy phase of the macro? Here is my macro:
Sub CommandButton1_Click()
‘
‘ Sub Interbranch()
‘
‘ InterbranchCopy Macro
‘ Macro recorded 11/09/2004 by bxwallac
‘
Dim DWB As Workbook
Dim CWB As Workbook
Dim SWB As Workbook
Dim DestinationBook As Variant
Dim SourceBook As Variant
Set CWB = ActiveWorkbook
SourceBook = Application.GetOpenFilename(FileFilter:=”All Excel Files,*.xls”, Title:=”Select Source File”)
If SourceBook = False Then
Exit Sub
End If
Set SWB = Workbooks.Open(SourceBook)
DestinationBook = Application.GetOpenFilename(FileFilter:=”All Excel Files,*.xls”, Title:=”Select Destination File”)
If DestinationBook = False Then
Exit Sub
End If
Set DWB = Workbooks.Open(DestinationBook)
CWB.Activate
Sheets(“Inter-Branch Allocation”).Range(“A1216:BI1251”).Copy DWB.Sheets(“Inter-Branch Allocation”).Range(“A1216”)
Sheets(“Detailed Financials”).Range(“AA82:BT82”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA82”)
Sheets(“Detailed Financials”).Range(“AA95:BT95”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA95”)
Sheets(“Monthly Plan Summary”).Range(“Y29:BR29”).Copy DWB.Sheets(“Monthly Plan Summary”).Range(“Y29”)
DWB.ActivateEnd Sub
Thank you.
-
WSsdckapr
AskWoody LoungerNovember 15, 2004 at 10:16 pm #900421You can keep the code as a separate routine. Then it would seem that you want to add the line:
DeleteAllVBA
right after the
CWB.Activate
Thus you would activate the “CWB” workbook. Then delete all the code from it. I don’t understand why this is an issue however. Copying the info from CWB to DWB should not be copying over any of the macro code from CWB to DWB.
Or am I missing something?
Steve
-
WScindypositano
AskWoody Lounger -
WScindypositano
AskWoody LoungerNovember 16, 2004 at 4:16 pm #900751Got it. My problem is I want to delete all VBA code from the destination file before the action to copy a range. This doesn’t work. Thank you.
‘ Sub Interbranch()
‘
‘ InterbranchCopy Macro
‘ Macro recorded 11/09/2004 by bxwallac
‘
Dim DWB As Workbook
Dim DestinationBook As String
Set CWB = ActiveWorkbook
DestinationBook = Application.GetOpenFilename(“All Excel Files,*.xls”)
Workbooks.Open DestinationBook
Set DWB = ActiveWorkbook
DeleteAllVBA
Sheets(“Inter-Branch Allocation”).Activate
ActiveSheet.Unprotect
Sheets(“Detailed Financials”).Activate
ActiveSheet.Unprotect
Sheets(“Monthly Plan Summary”).Activate
ActiveSheet.Unprotect
CWB.Activate
Sheets(“Inter-Branch Allocation”).Range(“A1216:BI1251”).Copy DWB.Sheets(“Inter-Branch Allocation”).Range(“A1216”)
Sheets(“Detailed Financials”).Range(“AA82:BT82”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA82”)
Sheets(“Detailed Financials”).Range(“AA95:BT95”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA95”)
Sheets(“Monthly Plan Summary”).Range(“Y29:BR29”).Copy DWB.Sheets(“Monthly Plan Summary”).Range(“Y29″)
DWB.Activate
ActiveWorkbook.ChangeLink Name:=”Interbranch 11-16-2004 Cindy.xls”, NewName:=DWB.FullName, Type:=xlExcelLinksEnd Sub
-
WSsdckapr
AskWoody LoungerNovember 16, 2004 at 5:04 pm #900787Could you be more specific about what doesn’t work?
I created a testfile, added some code and saved it. I uncommented your sub line (I don’t understand why the sub line is commented unless you have another sub line that you didn’t copy) and ran the code. I opened the testfile, and it deleted all the code in the file after it was opened.
Are you getting error messages? Is it deleting code from the wrong workbook? What is the symptom? “Doesn’t work” is pretty vague.
Have you created a reference to the “extensibility library” as described by Chip Pearson on the page I referenced? [fifth paragraph from the top]
Steve
-
WSGoCush
AskWoody LoungerNovember 17, 2004 at 7:43 am #901090I may have misunderstood the original question or the code, but>>>>
I understood the original poster wanted to start with the active workbook (CWB), open a 2nd wbk (DWB), delete all VBA from the DWB, then copy 3-4 ranges from the CWB into the DWB and finally close the DWB and move on to a new DWB where the procedure would be repeated.
The code appears to have a 3rd wbk involved SWB as the source of the ranges to be copied. — No sure if this is what is wanted.
Also, placing the DeleteVBA code after CWB.Activate will delete the code from the original workbook. BE VERY CAREFUL HERE !! ARE YOU SURE THIS IS WHAT YOU WANT?
-
WSGoCush
AskWoody LoungerNovember 17, 2004 at 7:43 am #901091I may have misunderstood the original question or the code, but>>>>
I understood the original poster wanted to start with the active workbook (CWB), open a 2nd wbk (DWB), delete all VBA from the DWB, then copy 3-4 ranges from the CWB into the DWB and finally close the DWB and move on to a new DWB where the procedure would be repeated.
The code appears to have a 3rd wbk involved SWB as the source of the ranges to be copied. — No sure if this is what is wanted.
Also, placing the DeleteVBA code after CWB.Activate will delete the code from the original workbook. BE VERY CAREFUL HERE !! ARE YOU SURE THIS IS WHAT YOU WANT?
-
WSsdckapr
AskWoody LoungerNovember 16, 2004 at 5:04 pm #900788Could you be more specific about what doesn’t work?
I created a testfile, added some code and saved it. I uncommented your sub line (I don’t understand why the sub line is commented unless you have another sub line that you didn’t copy) and ran the code. I opened the testfile, and it deleted all the code in the file after it was opened.
Are you getting error messages? Is it deleting code from the wrong workbook? What is the symptom? “Doesn’t work” is pretty vague.
Have you created a reference to the “extensibility library” as described by Chip Pearson on the page I referenced? [fifth paragraph from the top]
Steve
-
WScindypositano
AskWoody LoungerNovember 16, 2004 at 4:16 pm #900752Got it. My problem is I want to delete all VBA code from the destination file before the action to copy a range. This doesn’t work. Thank you.
‘ Sub Interbranch()
‘
‘ InterbranchCopy Macro
‘ Macro recorded 11/09/2004 by bxwallac
‘
Dim DWB As Workbook
Dim DestinationBook As String
Set CWB = ActiveWorkbook
DestinationBook = Application.GetOpenFilename(“All Excel Files,*.xls”)
Workbooks.Open DestinationBook
Set DWB = ActiveWorkbook
DeleteAllVBA
Sheets(“Inter-Branch Allocation”).Activate
ActiveSheet.Unprotect
Sheets(“Detailed Financials”).Activate
ActiveSheet.Unprotect
Sheets(“Monthly Plan Summary”).Activate
ActiveSheet.Unprotect
CWB.Activate
Sheets(“Inter-Branch Allocation”).Range(“A1216:BI1251”).Copy DWB.Sheets(“Inter-Branch Allocation”).Range(“A1216”)
Sheets(“Detailed Financials”).Range(“AA82:BT82”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA82”)
Sheets(“Detailed Financials”).Range(“AA95:BT95”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA95”)
Sheets(“Monthly Plan Summary”).Range(“Y29:BR29”).Copy DWB.Sheets(“Monthly Plan Summary”).Range(“Y29″)
DWB.Activate
ActiveWorkbook.ChangeLink Name:=”Interbranch 11-16-2004 Cindy.xls”, NewName:=DWB.FullName, Type:=xlExcelLinksEnd Sub
-
WSJohnBF
AskWoody LoungerNovember 16, 2004 at 8:51 pm #900908Cindy, you didn’t ask, but does your co-worker know that you can password protect code so that other users can’t view it? In the VBE, right click the VBAProject, select VBA Project Properties, Protection, check Lock Project for Viewing, and provide a password. Project security can be beaten only by a fairly obscure hacking technique, so for most work I’d trust it.
-
WSJohnBF
AskWoody LoungerNovember 16, 2004 at 8:51 pm #900909Cindy, you didn’t ask, but does your co-worker know that you can password protect code so that other users can’t view it? In the VBE, right click the VBAProject, select VBA Project Properties, Protection, check Lock Project for Viewing, and provide a password. Project security can be beaten only by a fairly obscure hacking technique, so for most work I’d trust it.
-
WScindypositano
AskWoody Lounger -
WSsdckapr
AskWoody LoungerNovember 15, 2004 at 10:16 pm #900422You can keep the code as a separate routine. Then it would seem that you want to add the line:
DeleteAllVBA
right after the
CWB.Activate
Thus you would activate the “CWB” workbook. Then delete all the code from it. I don’t understand why this is an issue however. Copying the info from CWB to DWB should not be copying over any of the macro code from CWB to DWB.
Or am I missing something?
Steve
-
WScindypositano
AskWoody LoungerNovember 15, 2004 at 8:42 pm #900375Ok, this is the code from Chip that is needed to delete the VBA code in the second file. Can you tell me where to paste it in my macro?
Code –
Sub DeleteAllVBA()Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponentsSet VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
Select Case VBComp.Type
Case vbext_ct_StdModule, vbext_ct_MSForm, _
vbext_ct_ClassModule
VBComps.Remove VBComp
Case Else
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Select
Next VBCompEnd Sub
Where do I paste the above code so it will remove the VBA code from the newly opened file before it starts the copy phase of the macro? Here is my macro:
Sub CommandButton1_Click()
‘
‘ Sub Interbranch()
‘
‘ InterbranchCopy Macro
‘ Macro recorded 11/09/2004 by bxwallac
‘
Dim DWB As Workbook
Dim CWB As Workbook
Dim SWB As Workbook
Dim DestinationBook As Variant
Dim SourceBook As Variant
Set CWB = ActiveWorkbook
SourceBook = Application.GetOpenFilename(FileFilter:=”All Excel Files,*.xls”, Title:=”Select Source File”)
If SourceBook = False Then
Exit Sub
End If
Set SWB = Workbooks.Open(SourceBook)
DestinationBook = Application.GetOpenFilename(FileFilter:=”All Excel Files,*.xls”, Title:=”Select Destination File”)
If DestinationBook = False Then
Exit Sub
End If
Set DWB = Workbooks.Open(DestinationBook)
CWB.Activate
Sheets(“Inter-Branch Allocation”).Range(“A1216:BI1251”).Copy DWB.Sheets(“Inter-Branch Allocation”).Range(“A1216”)
Sheets(“Detailed Financials”).Range(“AA82:BT82”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA82”)
Sheets(“Detailed Financials”).Range(“AA95:BT95”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA95”)
Sheets(“Monthly Plan Summary”).Range(“Y29:BR29”).Copy DWB.Sheets(“Monthly Plan Summary”).Range(“Y29”)
DWB.ActivateEnd Sub
Thank you.
-
WSsdckapr
AskWoody Lounger -
WSrory
AskWoody LoungerNovember 17, 2004 at 12:09 pm #901200Cindy,
Just for future reference, if you want to call any ASAP code from your own code, you can set a reference to the ASAP Utilities add-in (via Tools-References) and then call the procedure as normal – in your current example that would be something like:DWB.Activate Call ASAPUtilities.RemoveAllVBA
-
WSrory
AskWoody LoungerNovember 17, 2004 at 12:09 pm #901201Cindy,
Just for future reference, if you want to call any ASAP code from your own code, you can set a reference to the ASAP Utilities add-in (via Tools-References) and then call the procedure as normal – in your current example that would be something like:DWB.Activate Call ASAPUtilities.RemoveAllVBA
-
WScindypositano
AskWoody LoungerNovember 15, 2004 at 7:55 pm #900325ASAP Utilities is a free and easy to use Add-In for MS Excel 97/2000/2002/XP/2003. The utility contains over 300 functions to make your work easier, written by Bastien Mensink. I believe I got this info from one of the Woody posts. Anyway, there is a utility called System, Remove all macros/VBA code from current file. In my macro I first need to open the second file (which you helped me with.) Then, I need to remove all macros/VBA code from the newly opened file. with both files open I then run the macro to copy specific data. If I don’t use this utility, do you have code to remove all macros? BTW, You are brilliant! Thank you.
-
H. Legare Coleman
AskWoody Plus
-
-
WScindypositano
AskWoody LoungerNovember 15, 2004 at 7:07 pm #900268I believe this will do it. Thank you. Before I begin the action to copy data, in the newly opened file I want to run an ASAP utility called ‘System, Remove VBA Code’. After that I will then unprotect 3 specific sheets. Last step will to be to run the code to copy. Here’s the problem. Before I began writing the code, the utility ASAP was up on the menu. Now it is gone. How can I keep it on the menu so it can be included in the overall macro? Or do you have code that would remove VBA code from the newly opened file? I was going to place this code after the line ‘End If ‘ and before the line ‘Set DWB = Workbooks.Open(DestinationBook)’. Thank you.
-
-
-
WScindypositano
AskWoody LoungerNovember 15, 2004 at 5:58 pm #900223When I paste your code inside my macro, the code displays all on one line in red. The error message “Compile Error: Syntax Error” is displayed. Here is my current code. I need to open a file the line above this action. Thank you.
Sub CommandButton1_Click()
‘
‘ Sub Interbranch()
‘
‘ InterbranchCopy Macro
‘ Macro recorded 11/09/2004 by bxwallac
‘
Dim DWB As Workbook
Dim DestinationBook As String
Set CWB = ActiveWorkbook
DestinationBook = Application.GetOpenFilename(“All Excel Files,*.xls”)
Workbooks.Open DestinationBook
Set DWB = ActiveWorkbook
CWB.Activate
Sheets(“Inter-Branch Allocation”).Range(“A1216:BI1251”).Copy DWB.Sheets(“Inter-Branch Allocation”).Range(“A1216”)
Sheets(“Detailed Financials”).Range(“AA82:BT82”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA82”)
Sheets(“Detailed Financials”).Range(“AA95:BT95”).Copy DWB.Sheets(“Detailed Financials”).Range(“AA95”)
Sheets(“Monthly Plan Summary”).Range(“Y29:BR29”).Copy DWB.Sheets(“Monthly Plan Summary”).Range(“Y29”)
DWB.ActivateEnd Sub
-
-
H. Legare Coleman
AskWoody PlusNovember 15, 2004 at 5:19 pm #900198Is something like this what you are looking for?
Option Explicit Sub OpenTargetFile() Dim vTargetFile As Variant Dim wbkTarget As Workbook vTargetFile = Application.GetOpenFilename("Excel Files (*.xls),*.xls, All Files (*.*),*.*", _ 1, "Select Target File") If vTargetFile = False Then Exit Sub End If Set wbkTarget = Workbooks.Open(vTargetFile) End Sub
Viewing 3 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Very Quarrelsome Taskbar!
by
CWBillow
7 hours, 44 minutes ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
10 hours, 28 minutes ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
11 hours, 47 minutes ago -
Is your battery draining?
by
Susan Bradley
1 hour, 44 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
10 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
14 hours, 20 minutes ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
17 hours, 35 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
1 hour, 22 minutes ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
2 hours, 14 minutes ago -
National scam day
by
Susan Bradley
1 hour, 13 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
26 minutes ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
1 day, 15 hours ago -
Tools to support internet discussions
by
Kathy Stevens
4 hours, 5 minutes ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
1 day, 6 hours ago -
AI is good sometimes
by
Susan Bradley
1 day, 22 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
1 day, 12 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
2 days, 22 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
2 days, 21 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
3 days, 1 hour ago -
Excessive security alerts
by
WSSebastian42
1 day, 16 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
3 days, 10 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
1 hour, 8 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
2 days, 22 hours ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
1 day, 15 hours ago -
OS news from WWDC 2025
by
Will Fastie
1 day, 1 hour ago -
Need help with graphics…
by
WSBatBytes
2 days, 6 hours ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
4 days, 2 hours ago -
Totally remove or disable BitLocker
by
CWBillow
3 days, 1 hour ago -
Windows 10 gets 6 years of ESU?
by
n0ads
3 days, 4 hours ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
4 days, 13 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.