Need macro to insert workbook into another workbook using input box
Dave, opening and inserting the sheet works beautifully!
Deleting the sheet when the code starts is an elegant workaround!
Many thanks, you have helped immensely!
Mike
Dave Peterson wrote:
Deleting a worksheet when the workbook closes is a problem. If the user doesn't
save, then the the sheet isn't deleted. To make that automatic seems like more
of problem to me. If the user opens excel and closes and doesn't want to save,
should you force him/her.
How about just deleting the sheet when the code starts?
Something like:
Option Explicit
Sub testme()
Dim wkbk As Workbook
Dim tempWks As Worksheet
Dim myFileName As Variant
myFileName = Application.GetOpenFilename("Excel files, *.xls;*.csv")
If myFileName = False Then
Exit Sub
End If
Set wkbk = Workbooks.Open(Filename:=myFileName)
On Error Resume Next
Application.DisplayAlerts = False
ThisWorkbook.Worksheets("TempSheet").Delete
Application.DisplayAlerts = True
On Error GoTo 0
wkbk.Worksheets(1).Copy _
after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)
Set tempWks = ActiveSheet
tempWks.Name = "TempSheet"
'your code here.
End Sub
I am new to programming in Excel with VBA and I have spent 4 hours searching
the archives for a solution to my challenge.
[quoted text clipped - 20 lines]
Thanks,
Mike
|