Hi,
I have a function whereas I am copying sheets from another Workbook via VB, the sheets copy fine. However, I am having an issue where after I run this macro, every macro thereafter tries to re-open the Workbook which the sheets were copied from. I have a feeling an instance of Excel is running in the background, is it not closing the workbook properly? Below is sample code, any help would be greatly appreciated!
Public f_import As String
Public wBook_import As String
Public numSheets_import As Integer
Dim objApp As Excel.Application
Dim objBook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim fd As FileDialog
wBook_import = ThisWorkbook.Name
numSheets_import = ThisWorkbook.Worksheets.Count
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.Title = "Please Select Previous Forecast File"
.Filters.Clear
.Filters.Add Description:="Excel Forecast", Extensions:="*.xls", Position:=1
If .Show = True Then
f_import = fd.SelectedItems.Item(1)
'Import Archive Sheet
Dim openWorkbook As String
openWorkbook = f_import
Set objBook = Workbooks.Open(openWorkbook)
Set objApp = objBook.Parent
Set objSheet = objBook.Worksheets("Archive")
With objSheet
.Visible = True
.Copy After:=Workbooks(wBook_import).Sheets(numSheets_import) 'Copy after last worksheet in workbook
.Visible = False
End With
objBook.Close
Set objBook = Nothing
Set objApp = Nothing
Set objSheet = Nothing
End If
End With
Bookmarks