Macro Execution on Workbook Open

JCScoobyRS

Board Regular
Joined
Sep 17, 2002
Messages
102
Is there a way to fire off a macro once the workbook is opened? Something like an OnLoad() feature or Sub form_Load()? Thanks, Jeremy
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
That didn't work. Here is my code, any ideas:

Sub Auto_Open()
Dim OraSession As Object
Dim OraDatabase As Object
Dim QuoDynaSet As Object
Dim flds() As Object
Dim fldcount As Integer

Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase = OraSession.OpenDatabase("LIVE1", "*****/*****", 0&)
Set QuoDynaSet = OraDatabase.CreateDynaSet("select CU_NAME from CU", 0&)

Range (AK1)
Selection.ClearContents
'Declare and create an object for each column.
'This will reduce object reference and speed
'up your application.

fldcount = QuoDynaSet.Fields.Count
ReDim flds(0 To fldcount - 1)
For Colnum = 0 To fldcount - 1
Set flds(Colnum) = QuoDynaSet.Fields.Count - 1

Next
'Insert Column Headings
For Rownum = 2 To QuoDynaSet.Fields.Count - 1
ActiveSheet.Cells(1, Colnum + 1) = flds(Colnum).Name

Next

'Display Data
For Rownum = 2 To QuoDynaSet.RecordCount + 1
For Colnum = 0 To fldcount - 1
ActiveSheet.Cells(Rownum, Colnum + 1) = flds(Colnum).Value

Next

QuoDynaSet.MoveNext

Next

Range(AK1).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,222,246
Messages
6,164,805
Members
451,917
Latest member
WEB78

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