Hey guys,
I need help with adjusting my macro. Basically it opens a file and then copies content. However before doing the copying, I want it to check if on the file it opened whether the content of G1 is "pass". If it is pass to run the macro "Adjust" on that workbook.
How do I do that? I tried with:
If ActiveWorkbook.Worksheets("Target").Cell("G1") = "pass" Then Application.Run ActiveWorkbook.Name & "!Adjust"
but it gives me an error
Option Explicit
Sub test()
Dim wb As Workbook, wb2 As Workbook
Dim ws As Worksheet
Dim vFile As Variant
'Set source workbook
Set wb = ActiveWorkbook
'Open the target workbook
vFile = Application.GetOpenFilename("Excel-files,*.xls", _
1, "Select One File To Open", , False)
'if the user didn't select a file, exit sub
If TypeName(vFile) = "Boolean" Then Exit Sub
Workbooks.Open vFile
'Set targetworkbook
Set wb2 = ActiveWorkbook
If ActiveWorkbook.Worksheets("Target").Cell("G1") = "pass" Then Application.Run ActiveWorkbook.Name & "!Adjust"
Thank you in advance!
P.S.:
Okay, found it. It works fine this way:
If ActiveWorkbook.Worksheets("Target").Range("G1").Value = "pass" Then Application.Run ActiveWorkbook.Name & "!Adjust"
Bookmarks