I’m trying to enable a macro that allows us to import information from a subassembly into its relevant parent test document.
Both are Excel (XLSM) files with Macros, and I’m having some trouble identifying how to adequately open the target file, copy the cells over (all have cell Names to help with later data mining), and close the original file. For now, it’s only a few cells, but I want to keep it expandable for future use.
Sample code is below, and I can’t seem to figure out why it doesn’t work. Any help is appreciated.
I’ve tried each of the following snippets but get Error 436 when attempting to run (although the target file does open).
Sub ImportRNSData() With Application.FileDialog(msoFileDialogFilePicker) 'Makes sure the user can select only one file .AllowMultiSelect = False 'Filter to just the following types of files to narrow down selection options .Filters.Add "RNS eFAT Files", "*.xlsm", 1 'Show the dialog box in the local directory .Title = "Open RNS eFAT File" .Show 'Store in fullpath variable fullpath = .SelectedItems.Item(1) End With Workbooks.Open (fullpath) '<--this is where the debugger sends me Workbooks(fullpath).Worksheets("System Config").Range("SerialNumber").Copy _ ThisWorkbook.Worksheets("Test Section").Range("SNFV_Seeder") End Sub
For the workbook open section, I've also tried the following code:
Dim Wb1 As Workbook Application.ScreenUpdating = False Set Wb1 = Workbooks.Open(fullpath) 'open workbook <--this is where the debugger sends me Wb1.Sheets(2).Range("SerialNumber").Copy Wb1.Close SaveChanges:=False ThisWorkbook.Sheets(5).Range("SNFV_Seeder").PasteSpecial Paste:=xlPasteAll Application.ScreenUpdating = True