what does this VB program mean

S

subs

Public Sub AddTitles(strFile As String, intRows As Integer,
astrTitles() As
String)
On Error GoTo Err_AddTitles


Dim appExcel As Excel.Application
Dim bksBooks As Excel.Workbooks
Dim wkbBook As Excel.Workbook
Dim wksSheet As Excel.Worksheet
Dim intArrRow As Integer


'Initiate all objects and variables
Set appExcel = GetObject(, "Excel.Application")
Set bksBooks = appExcel.Workbooks
Set wkbBook = bksBooks.Open(strFile)
Set wksSheet = wkbBook.Sheets(1)
wksSheet.Activate
ActiveCell.Rows("1:" & intRows + 1).EntireRow.Select
Selection.Insert Shift:=xlDown,
CopyOrigin:=xlFormatFromLeftOrAbove
For intArrRow = 0 To intRows - 1
Range(astrTitles(intArrRow, 0)) = astrTitles(intArrRow, 1)
Next intArrRow
appExcel.Visible = True


Exit_AddTitles:
Exit Sub


Err_AddTitles:
If Err.Number = 429 Then 'excel not running
Set appExcel = CreateObject("excel.application")
Resume Next
Else
Call gsgErrorHandling
Resume Exit_AddTitles
End If


End Sub


This above code is supposed to export access report into a excel
report. Should i put this code as a macro? pls help
 
N

Noëlla Gabriël

Hi,

it opens an excel workbook from within access, and then switches to the
excel object model and adds a few rows in the excel workbook with access data.
 
B

Bob Barrows [MVP]

subs said:
Public Sub AddTitles(strFile As String, intRows As Integer,
End Sub


This above code is supposed to export access report into a excel
report. Should i put this code as a macro? pls help

No, VBA code does not go into a macro: it goes into a module. Click into the
Modules tab on the database window. Click the New button and the VBA IDE
(editor) will open. Paste your subroutine (sub) into the window. Close and
save the new module - give it a different name from the name of your sub,
i.e., do not call the module "AddTitles". You can add other functions and
subs to this module so there is no point to calling it "AddTitles". Unless I
am planning on adding multiple modules to a database, I will usually just
leave the name as Module1.

Now, you will be able to call (execute) this sub from an event procedure in
a form's module.

For more assistance, post to the relevant VBA newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top