This code is working beautifully except for the last step where I am trying to rename the copied worksheet to what the user chose to name it in the inputbox. Any suggestions appreciated. Error is something like "Object variable not defined". Here's my code:
Code:Sub COPY_FROM_MainSched_TO_DoorSched() 'Declare variables Dim SourcePath, SourceFile, SourceWbk, MSG, NewShtName As String Dim destsheet, srcsheet As Workbook Dim NewSht As Worksheet 'set variables SourcePath = "H:\schedule\" SourceFile = "Cabot, S.xls" SourceWbk = SourcePath & SourceFile 'Disable alerts & screen updating Application.DisplayAlerts = False Application.ScreenUpdating = False 'Copy the sheet from the source workbook to the destination workbook Set destsheet = ActiveWorkbook Set srcsheet = Workbooks.Open(SourceWbk) srcsheet.Worksheets.Copy _ after:=destsheet.Sheets(destsheet.Sheets.Count) srcsheet.Close True 'Ask the user what they would like to name the copied sheet NewShtName = InputBox(prompt:="Please enter a name for the new worksheet") 'Check if the user has entered a name While NewShtName = "" 'name field has been left blank MSG = MsgBox(prompt:="Worksheet name required!", Buttons:=vbOKOnly + vbExclamation) NewShtName = InputBox(prompt:="Please enter a name for the new worksheet") Wend 'Rename the worksheet NewSht = ActiveWorkbook.Worksheets("Log (2)") NewSht.Name = NewShtName End Sub




Reply With Quote