Rowland Hamilton
Active Member
- Joined
- Nov 13, 2009
- Messages
- 250
Folks:
I want to add this functionality to my code:
VBA file browser command to open any workbook to define as SourceWB
What is the easy way to add this functionality to the following code (Or the most efficient way to do what this code does and add this functionality to it)?:
I saw this thread but have't figured out if this is the way to go:
http://www.mrexcel.com/forum/showthread.php?t=566120&highlight=vba+file+browser+code
Thank you - Rowland
I want to add this functionality to my code:
VBA file browser command to open any workbook to define as SourceWB
What is the easy way to add this functionality to the following code (Or the most efficient way to do what this code does and add this functionality to it)?:
Code:
Sub Populate_line_item_workbooka()
Dim MasterWB As Workbook
Dim SourceWB As Workbook
Dim ws As Worksheet
Set MasterWB = Workbooks("Line items-Combined.xlsm")
Application.DisplayAlerts = False
'we need to let excel know the Work book then we can define it as SourceWB
Workbooks.Open FileName:=ThisWorkbook.path & "\" & "United States (de linked).xlsm", _
UpdateLinks:=0
Set SourceWB = Workbooks("United States (de linked).xlsm")
'ActiveWorkbook.Names("MyRange").Name Like "*!*"
SourceWB.Activate
Application.DisplayAlerts = False
On Error GoTo ErrorCatch
For Each ws In SourceWB.Worksheets
'MsgBox (Mid(ws.Name, 5, 10))
'Here I am not sure of like *-Line item* so I change to be If Mid(ws.Name, 5, 10) = "-Line item" Then
'If Mid(ws.Name, 5, 10) = "-Line item" Then 'note: Mid formula won't work bc varying number characters for cc
If ws.Name Like "*-Line item*" Then
ws.Select
Range("A3").Select
' the sub is only short one, so no need to splite it into 2 subs, otherwise we need to activate the Windows("Line items-Combined.xlsm") again before redefine it as SourceWB, then we can use SourceWB
'copy
Range("A3").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
'paste
MasterWB.Activate
Sheets("Master-Incoming").Activate
Range("A65000").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
SourceWB.Activate
'Exit for...No need to be Exit for here, for each......then will loop until last object in for is performed then it will stop itself.
End If
Next ws
MasterWB.Activate
ErrorCatch:
SourceWB.Activate
Application.CutCopyMode = False
Range("A1").Select
MasterWB.Activate
Range("A1").Select
MsgBox ("No More Sheets To Copy") 'Err.Description
End Sub
I saw this thread but have't figured out if this is the way to go:
http://www.mrexcel.com/forum/showthread.php?t=566120&highlight=vba+file+browser+code
Thank you - Rowland