activating a sheet from workbook open

Wesj43

New Member
Joined
May 21, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I am once again new to Excel VBA not having had to program it for the last 15 years. Suddenly I find I must return to my former profession and find I have lost a lot of knowledge. (If I ever had it LOL) So I am basically a noob.

I am having an issue with activating a sheet from the workbook open process. Here is my opening code

VBA Code:
Private Sub workbook_open()
' MsgBox ("Workbook is Open")
Call MySaveAs
' Find Last row
'use End(xlUp) to determine Last Row with Data, in one column (column A)
'Rows.count returns the last row of the worksheet
lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row
lastRow = lastRow + 1 ' found last row with data now point to next empty row
' MsgBox ("last Row is ") & lastRow
MsgBox ("Activate Sheet")
' Activate a Sheet
ThisWorkbook.Sheets("Sheet1").Activate
MsgBox ("activated sheet")
' break code here
' Stop
End Sub

Everything works great except the macro on the activated sheet never fires.

VBA Code:
Public Sub worksheet_activate()
MsgBox ("got to worksheet")
' MsgBox ("Format row")
Call formatrow
MsgBox ("Format Done")
' break code here
Stop
Call Get_Input
End Sub

I never get the "Got to Worksheet" msg.

I am sure I am forgetting something simple

Any help is much appreciated.

Thanks to all

Wes
 
Last edited by a moderator:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Is the worksheet_activate() SUB declared in the worksheet module for Sheet1 or did you add the SUB to a standard module by mistake ?
 
Upvote 0
Is the worksheet_activate() SUB declared in the worksheet module for Sheet1 or did you add the SUB to a standard module by mistake ?
Thanks for the quick reply

Yes it is declared in the Sheet1(sheet1) object
 
Upvote 0
Thanks for the quick reply

Yes it is declared in the Sheet1(sheet1) object
Wy is the worksheet_activate() Public ? It should be Private by default.... That looks doggy to me and made me suspect it was in the wrong object module.

Is the MySaveAs routine disabling excel events at any point ?
 
Upvote 0
No I don't believe it is. Here is the code

VBA Code:
Private Sub MySaveAs()
' Save backup
    Dim strFolder As String
    Dim i As Long
    Dim Filename As String
    Dim folderpath As String

'Find the position of the period in the file name
    i = InStr(ActiveWorkbook.Name, ".")
'Create a default file name by concatenating the file name without the extention _
        plus the current date and time, and plus the xlsm extention
    Filename = Left(ActiveWorkbook.Name, i - 1) & "_" & Format(Now, "yyyy-mm-dd_hh_mm") & ".xlsm"
' MsgBox ("File name = ") & Filename
'Open Save As dialog to a default folder with default file name
With Application.FileDialog(msoFileDialogSaveAs)
    .AllowMultiSelect = False
    .InitialFileName = "C:\Documents\" & Filename
    .InitialView = msoFileDialogViewDetails
If .Show = -1 Then
    strFolder = .SelectedItems(1)
Else
    Exit Sub
End If
'get selected folder path from FileDialog, but remove filename from FileDialog
        folderpath = Left(strFolder, InStrRev(strFolder, "\"))
' MsgBox ("folderpath = ") & folderpath
'Save this workbook in chosen file path & appropriate filename
        'File format .xlsm
    ThisWorkbook.SaveCopyAs Filename:=folderpath & Filename 'FileFormat:=xlOpenXMLWorkbookMacroEnabled
' MsgBox ("Filename = ") & Filename
End With

End Sub
 
Upvote 0
Changed the Macro to Private, but no joy. Not sure why I made it Public.
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top