0

sorry if my question is an easy one. I am still getting the hang of vba.

Is there anyway to have a macro select a workbook defined by the user, then use that range for calculations? An example of what I am trying to do is in the code below:

Sub Other_Workbook_Range()

    Dim wb As String
    wb = Application.GetOpenFilename

    If Range("A1").Value = Workbooks(wb).Worksheets("Sheet 1").Range("H74").Value Then

        MsgBox "Okay"

    Else

        MsgBox "Fix"

    End If

End Sub

I don't think this code will work, but it is the best example I have of what I am trying to do. Let me know if I can clarify further. Thank you for your help in advance!

Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
Zac M
  • 1
  • 1
    GetOpenFilename method displays the standard Open dialog box and retrieves a file name specified from a filtered list provided by the user. https://msdn.microsoft.com/en-us/library/office/hh710200(v=office.14).aspx#odc_xl4_ta_ProgrammaticallySelectFileforMac_IntroducingGetOpenFileNameMethod – QHarr Mar 28 '18 at 19:08
  • Are you intending to have the user select from a dialog box? – QHarr Mar 28 '18 at 19:09
  • 1
    ^ what he said. You still need to `Set wb = Application.Workbooks.Open(path)` (assuming `Dim path As String` and `Dim wb As Workbook`, and `path = Application.GetOpenFilename`) - and then you can do `wb.Worksheets("Sheet 1").Range(whatever)` – Mathieu Guindon Mar 28 '18 at 19:10
  • Do you compare the range from the selected book with an already open book ?, or does the comparation correspond to different sheets of the same selected book ? – jsanchezs Mar 28 '18 at 19:41
  • Thanks! Mathieu Guindon, you have answered my question. Adding in the code using your assumptions worked. Would you like me answer my question using your comment or edit my question to include your comment as an answer? – Zac M Mar 28 '18 at 19:49

0 Answers0