
Translating Excel VBA to VB5 code ?
Rod,
I have used Visual Basic to generate Excel files often and the conversion
between Excel VB Code and Visual Basic code is not an issue as long as you
remember that when inside the Macro writer in Excel you are working with the
ActiveSheet so in Visual Basic you got to create an active sheet.
Example of some VB Code :
dim objExcelApp, wbWorkBook, stSheet as Object
:
:
:
Set objExcelApp = CreateObject("Excel.Application")
objExcelApp.Workbooks.Add
Set wbWorkBook = objExcelApp.ActiveWorkbook
wbWorkBook.Sheets(1).Activate
Set stSheet = wbWorkBook.Sheets(1)
' --- General Excel formatting
frmStatus.SetText "Placing Headings.", False
With stSheet.Cells
.Font.Name = "Times New Roman"
.Font.Size = 8
End With
nCurrRow = 1
With stSheet.Cells(nCurrRow, 1)
.Font.Size = 12
.Font.Bold = True
.Value = "Fax Log Report"
End With
:
' --- Here is a Chart !!!
' Place the Charts
objExcelApp.ActiveSheet.ChartObjects.Add(634.5, 0, 630, 439.5).Select
objExcelApp.ActiveChart.ChartWizard Source:=stSheet.Range("A6:C" & nCurrRow
- 2), Gallery:=xlColumn, _
Format:=6, PlotBy:=xlColumns, CategoryLabels:=1, SeriesLabels:=1,
HasLegend:=1, _
Title:="Diallings and DMs for Telemarketing - " & Format$(dateCurrent,
"d mmm, yyyy"), _
CategoryTitle:="Agents", ValueTitle:="", ExtraTitle:=""
:
:
objExcelApp.ActiveSheet.PrintOut
frmStatus.SetText "Saving File : " & szFileName & ".", False
If Dir(szFileName) <> "" Then
Kill szFileName
End If
wbWorkBook.SaveAs szFileName
wbWorkBook.Close
objExcelApp.Quit
Set wbWorkBook = Nothing
Set objExcelApp = Nothing
Hope this helps,
Eamonn J.
Quote:
>Hello everyone.
>I want to create a chart in Excel from some data in VB5. I put the
>data onto the clipboard and tell Excel to paste it. I then captured a
>macro that's the result of the chart wizard.
>I now want to use this VBA code inside VB5 to automate the process.
>Is there a simple way to translate the VBA code to VB5? Doing
>something like Set Excel = CreateObject("Excel.Sheet") and then using
>Excel.AddChart works OK, but some of the objects that VBA uses are
>very tricky to map into VB5.
>Or am I going about this the wrong way? (i.e. should I keep the VBA
>code and have VB5 tell Excel to start the macro?).
>TIA
>Rod