Marc Chevalier
asked on
Excel 365 spreadsheet not initializing field values with Private Sub AutoOpen command?
I have a simple spreadsheet with 5 fields on it that is to be used as an entry form for printing. The idea is the user just opens the spreadsheet, fills in the fields, and clicks on the PRINT button at the bottom of the spreadsheet to print the simple form. I am using excel 365 and I put some simple VBA code on the spreadsheet to initialize the 5 fields as the spreadsheet opens, but it does not initialize the fields? This is the code I am using:
Private Sub AutoOpen_()
Range("C3").Select
Range("C3").Value = " "
Range("B5").Select
Range("B5").Value = " "
Range("F5").Select
Range("F5").Value = " "
Range("B9").Select
Range("B9").Value = " "
Range("B10").Select
Range("B10").Value = " "
Range("B11").Select
Range("B11").Value = " "
MsgBox ("AutoOpen")
End Sub
I have also placed the spreadsheet in a trusted directory and saved it as an xlsm type spreadsheet. I don't understand why it is not working?
Private Sub AutoOpen_()
Range("C3").Select
Range("C3").Value = " "
Range("B5").Select
Range("B5").Value = " "
Range("F5").Select
Range("F5").Value = " "
Range("B9").Select
Range("B9").Value = " "
Range("B10").Select
Range("B10").Value = " "
Range("B11").Select
Range("B11").Value = " "
MsgBox ("AutoOpen")
End Sub
I have also placed the spreadsheet in a trusted directory and saved it as an xlsm type spreadsheet. I don't understand why it is not working?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Okay, so that makes sense that Office 365 no longer works with macros. So is my only work around to go back to a previous desktop version, period?
Yes, The office 365 currently doesn't support that..You need to go to desktop version.
Saurabh...
Saurabh...
Okay, so that makes sense that Office 365 no longer works with macros. So is my only work around to go back to a previous desktop version, period?
...or a current "desktop" version.
When you do, however, note my first comment about naming the subroutine(s) that will execute Visual Basic for Applications code statements once the person opening the MS-Excel workbook has confirmed that macro-support should be enabled.
ASKER
Thanks for that fanpages. Honestly I don't know the difference between coding a ThisWorkbook code module area and the Public (Global) Code Module? I rarely do any of this and don't know how to setup one versus the other type, ThisWorkbook vs Public(Global)? Can you help?
mjchevalier,
To keep it simple and short in thisworkbook module you will put all the codes which you want to trigger at a particular event..they can only be triggered from thisworkbook module for instance when you open or close or the save workbook... They can't be triggered from the Standard module..
Standard modules are for running code triggered by user interaction only...
Saurabh...
To keep it simple and short in thisworkbook module you will put all the codes which you want to trigger at a particular event..they can only be triggered from thisworkbook module for instance when you open or close or the save workbook... They can't be triggered from the Standard module..
Standard modules are for running code triggered by user interaction only...
Saurabh...
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks all for the good information. This morning I contacted Microsoft and told them I was using Office 365 Home 2016 and that since we began using Office 365, the macro-enabled spreadsheets that I create do not work. The rep asked me if I had any macro enable spreadsheets that work and I said yes, but they were created with a standalone version of Office 2013. Office 2013 was uninstalled automatically when Office 365 2016 was installed. He cut me off right there and said my new files were corrupted and would not answer my direct question of; Does Office 365 2016 support the use of macros?
I am very frustrated right now because I don't know what is really going on here. I have a simple spreadsheet that has some simple code set up to initialize the spreadsheet fields upon opening, yet it just won't initialize. The code is under the 'View code' section of the spreadsheet with the upper box on the left showing 'General' and the upper box on the right showing 'Auto_Open'. If I select the code and click on run in the VBA section, it works fine, it just won't run when I open the spreadsheet.
Thanks for any help you can give me.
I am very frustrated right now because I don't know what is really going on here. I have a simple spreadsheet that has some simple code set up to initialize the spreadsheet fields upon opening, yet it just won't initialize. The code is under the 'View code' section of the spreadsheet with the upper box on the left showing 'General' and the upper box on the right showing 'Auto_Open'. If I select the code and click on run in the VBA section, it works fine, it just won't run when I open the spreadsheet.
Thanks for any help you can give me.
In which module (ie what is the module name) is the code located?
I don't think the rep knew what he was talking about based on your description. Did you get his name?
I don't think the rep knew what he was talking about based on your description. Did you get his name?
ASKER
Thanks but actually I don't know how to tell what module it is in? I just went to show code and typed the code in?
ASKER
At the top of the screen when you are viewing code, it has a drop down on the left that shows 'General' and the drop down to the right of that shows 'Auto_Open'.
Which module is highlighted in the project Explorer when your cursor is in the code? I suspect you put it in a worksheet module not a normal module.
I've requested that this question be closed as follows:
Accepted answer: 250 points for fanpages's comment #a41387427
Assisted answer: 250 points for rorya's comment #a41389772
for the following reason:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Accepted answer: 250 points for fanpages's comment #a41387427
Assisted answer: 250 points for rorya's comment #a41389772
for the following reason:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Thanks Martin,
Comments from saurabh726 & rorya were selected instead.
Comments from saurabh726 & rorya were selected instead.
Should be either:
a) Within the ThisWorkbook code module & defined as Private Sub Workbook_Open()
or
b) Within a Public (Global) code module & defined as Public Sub Auto_Open()