Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88081

Activate a workbook opened via file dialog

$
0
0

I am trying to open a workbook using the file dialog option and then activate the newly opened workbook and conduct further macros between the new one and the currently open one.

    Dim QTM As String
    Dim SARFName As String
    Dim Open2 As Office.FileDialog
    Dim nameLocation As Integer
    Dism Shex As Object

    QTM = ActiveWorkbook.Name

     Set Open2 = Application.FileDialog(msoFileDialogFilePicker)

   With Open2

      .AllowMultiSelect = False
      .Title = "Please select the most recent SARF."
      .Filters.Clear
      .Filters.Add "", "*.xls; *.xlsx; *.xlsm"
      .Filters.Add "All Files", "*.*"

      If .Show = True Then
        SARF = .SelectedItems(1)
      End If
   End With

Set Shex = CreateObject("Shell.Application")
Shex.Open (SARF)

SARFName = Split(SARF, "\")(UBound(Split(SARF, "\")))
Workbooks(SARFName).Activate

.
.
.
etc.

I know SARFName is the correct file name without the directory, but upon Workbooks(SARFName).Activate, it returns a runtime error 9 subscript out of range.

My end goal is to be able to either activate QTM or SARF and perform some actions within their sheets.

Thanks


Viewing all articles
Browse latest Browse all 88081

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>