baralus
03-09-2018, 09:52 PM
So i have this code that can open any workbook by opening the document browser, and i set a condition that if its not the right filename the process wont continue. But on my code i can only open the workbook first before checking if it has the right filename. Is their a way to check the filename first before opening it? i just want to make it look more dynamic by placing the process in order.
Sub myfile()
Dim wb As Workbook
Dim ws As Worksheet
Dim twb As Workbook
Set twb = ThisWorkbook
file = Application.GetOpenFilename("Excel Files (*.xlsm; *xlx; *xlsx), *.xlsm; *.xlx; *xlsx")
Set wb = Workbooks.Open(file)
If wb.Name = "Book1.xlsm" Then
For Each ws In wb.Sheets
ws.Columns(1).Copy
twb.Sheets("sheet6").Columns(1).PasteSpecial
wb.Close
Next
Else
MsgBox "Not the right Workbook"
wb.Close
End If
End Sub
Sub myfile()
Dim wb As Workbook
Dim ws As Worksheet
Dim twb As Workbook
Set twb = ThisWorkbook
file = Application.GetOpenFilename("Excel Files (*.xlsm; *xlx; *xlsx), *.xlsm; *.xlx; *xlsx")
Set wb = Workbooks.Open(file)
If wb.Name = "Book1.xlsm" Then
For Each ws In wb.Sheets
ws.Columns(1).Copy
twb.Sheets("sheet6").Columns(1).PasteSpecial
wb.Close
Next
Else
MsgBox "Not the right Workbook"
wb.Close
End If
End Sub