Translating Excel VBA to VB5 code ? 
Author Message
 Translating Excel VBA to VB5 code ?

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



Sun, 02 Jan 2000 03:00:00 GMT  
 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



Sun, 02 Jan 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Translating FORTRAN code into VBA code

2. EXCEL source code in VB5.0 and VBA

3. Translate WordBasic AppShow in a real VBA-Code

4. VBA code in Excel 97 vs Excel 2002

5. Running VBA code in EXcel from VB6 using EXcel Objects

6. VBA coding to call an Excel VBA macro from Outlook

7. Windows EXCEL VBA / MAC EXCEL VBA compatibility issues

8. Excel 97 VBA vs Excel 2000 VBA

9. VBA Code to add text to shapes in Excel

10. vba code to copy table from access 97 to excel 97

11. Executing Excel-VBA code within a Access-database

12. VBA code to close ALL instances of Excel

 

 
Powered by phpBB® Forum Software