PDA

View Full Version : Load database values into Worksheet



JimFl78
03-14-2008, 08:34 AM
Hi,

Can anybody tell me the best method to load or set values on my worksheet using VBA when I open the worksheet from scratch?

I have tried all sorts of initialisation but as I havent been working with VBA for a while I have not been able to do so. Im sure its simple but struggling on this one.

Many thanks in advance

JimFl78

Aussiebear
03-14-2008, 08:53 AM
Can you give us an example of how you want the data laid out on the sheet and where is the data currently stored?

JimFl78
03-14-2008, 09:38 AM
At the moment I currently have a button that will load my database values into the worksheet. I have no porblem connecting to my database and retrieving and placing the values in the relevant cells.

However I would like the function to automatically load this when the excel sheet is first loaded. I am not sure how to do this.

Elements of my project

Sheet 1
Module - this contains the events for my button click. I will need to place this code on the event like worksheet_load. However I have tried this without any luck. The problem is that I am trying to find the event that I can use to trigger the load once the project is opened and where this event code will exist in my project. Ie in the Sheet1 code or the module code ?

I hope this helps to clarify a bit more what I am trying to achieve.

Dr.K
03-14-2008, 11:34 AM
Worksheet-level events don't trigger when a workbook opens. You need to use a Workbook-level event.

Use the "Workbook_Open" event; put it in the "ThisWorkbook" code pane.


Private Sub Workbook_Open()