Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > PC based Database Applications > Microsoft Excel > How to script an exisiting Excel sheet into VBA?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-08, 10:52
Wim Venema Wim Venema is offline
Registered User
 
Join Date: Jun 2004
Location: Lichtenvoorde, Netherlands
Posts: 35
Question How to script an exisiting Excel sheet into VBA?

Hi,

I often use macros in Excel and have many sheets that I use as template to
fill-in automatically figures from a MSSQL database.
I want to integrate the templates into the macro itself.
This makes the deployment of the application easier by just updating one Excel add-in.
Does anyone know how automatically script an exsisting Excel Sheet into VBA (including, formulas, graphs etc)?
This will save me a lot of work converting the templates into VBA.
Reply With Quote
  #2 (permalink)  
Old 10-06-08, 18:07
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 525
The best approach to this is to separate your VB Procedures from the data and the templates, then refer to the template in the code as a workbook.Worksheet or use ActiveSheet ActiveWorkbook references in your code. What you will end up with is a standard Template that will be used to create each report, a code file may be an add-in, and your database which you are already referencing. You may have to do some jockying around depending on how you are calling the data if you are using GetExternal Data with MS Query. But the idea is to separate the code / data / display template into 3 parts. This will make it much easier to maintian your process and distribute it.

Here's an example of code reference to the target worksheet where the data will be written:
Code:
strTemplate = Thisworkbook.Path & "MyCoolTemplate.xls" Workbooks.Open(strTemlate) ActiveWorkbook.Sheets(1).Activate Set targWS = ActiveWorksheet ' Write some headers For i = 1 to 4 targWS.Cells(1, i).Value = "Fields" & i Next
__________________
~

Bill
Reply With Quote
  #3 (permalink)  
Old 10-14-08, 22:07
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,080
Excellent advice, Bill! Same goes for data setup within Excel itself. Makes for much more flexible and powerful approach.
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On