Run VBA

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
675
Office Version
  1. 365
Platform
  1. Windows
hi

i have taken ownership of a workbook . I need the VBA to run upon opening the file can someone advise on how to do this?

I thought I just had add the applicable into 'thisworkbook' but it does not run upon opening:banghead:

MTIA & KR
Trevor3007:cool:
 
Last edited:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
It looks like you ran into trouble, and your full question did not get posted. Can you try again?
 
Upvote 0
It looks like you ran into trouble, and your full question did not get posted. Can you try again?

good evening joe4

thanks fr your advise.

I have some VBA but rather than use a macro button to invoke, I would rather have the vba to kick in upon opening the file.

this the code i have

Code:
Sub GetFilePath()

    Dim dialogBox As FileDialog
    Set dialogBox = Application.FileDialog(msoFileDialogOpen)
        
    Call GetInputs
          
    'Do not allow multiple files to be selected
    dialogBox.AllowMultiSelect = False
    
    'Set the title of of the DialogBox
    dialogBox.Title = "Select a file"
    
    
    'Set the initial path to :
    dialogBox.InitialFileName = "C:\Users\datw as from May2018\EmailExcelTemplate.xlsm"
    
    'Show the dialog box and output full file path and file name
    If dialogBox.Show = -1 Then ActiveCell.Value = dialogBox.SelectedItems(1)


KR
Trevor3007
 
Upvote 0
Use the Workbook_Open event procedure, which is VBA code that is automatically fired when the file is opened.

See here: http://access-excel.tips/excel-workbook-open-event/

Evening Joe44,

many thanks again. So sorry but in my previous I pasted in the wrong code:{ It should of been:-


[/CODE]Private Sub GetInputs()

With Sheets("timesheet")
.Select
.Cells(2, 1).Value = InputBox("Please enter date value: ")
End With

With Sheets("timesheet")
.Select
.Cells(2, 2).Value = InputBox("Enter 1st Monday In Period: ")
End With



With Sheets("Sheet1")
.Select
.Cells(2, 8).Select
MsgBox "Attach file", vbOKOnly
End With

End Sub
[/CODE]

I checked out the link you sent but I do not have any idea on how to? I did try and all I managed to do is mess up my workbook:banghead:


Can you assist further please?

Oh.. there is also other code within the workbook too. But the above is the one I need to run when the workbook is open.

MTIA & KR
Trevor3007:cool:
 
Upvote 0
Just take the body of the VBA code that you already have and put it in the "Workbook_Open" procedure, as shown in the link I provided.
Just note that this has to be done in the "ThisWorkbook" module in VBA.
 
Upvote 0
Just take the body of the VBA code that you already have and put it in the "Workbook_Open" procedure, as shown in the link I provided.
Just note that this has to be done in the "ThisWorkbook" module in VBA.



hi Joe4,

thanks for your help. Good to say that I am now sorted and many thanks again:beerchug:

Have a great day.
KR
Trevor3007:cool:
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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