Results 1 to 7 of 7
  • Thread Tools
  1. 4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB6 opening excel in w95 (w95/w2000)

    I wrote a small vb6 program that works fine on w2000. When i try on w95 i get "this program performed illegal operation" when i hit the submit button.

    Private Sub imgSubmit_click()
    Dim xlsApp As Excel.Application
    Dim wb As Workbook


    'code to make sure no other instance of excel is open

    'open the contact xls
    Set xlsApp = New Excel.Application
    ' xlsApp.Visible = True
    Workbooks.Open FileName:="c:contacts.xls"
    Call AddToExcel
    ActiveWorkbook.Close SaveChanges:=True
    xlsApp.Quit
    Set xlsApp = Nothing
    Call ClearTextBoxes
    If MsgBox("Contact has been entered, do you want to enter another?", vbYesNo) = vbNo Then
    End
    End If

    End Sub

    Private Sub AddToExcel()

    Dim rngData As Range
    Dim rngRow As Range
    Dim lastRow As Integer

    Worksheets("Data").Activate
    Set rngData = Range("A3").CurrentRegion

    lastRow = rngData.Rows.Count + 1
    Range("A" & lastRow) = txtDate.Text

    end sub

    What am i doing wrong? thank you for the help

  2. Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 opening excel in w95 (w95/w2000)

    Word 95 used Wordbasic- a Basic-like language- which was easier to learn than VBA but which was far less powerful. I'm not even sure if you can do what you want in Wordbasic.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  3. 4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 opening excel in w95 (w95/w2000)

    by w95 i meant windows 95. I tried to use the code with w95 and word97 and it bombed. thanks

  4. Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VB6 opening excel in w95 (w95/w2000)

    Can you narrow it down to the line that causes the crash? Annoying ways to do this include putting a MsgBox after each line in the most likely area or writing to a log file as you go. If there is an elegant way to do it, I'm not aware of it.

  5. Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 opening excel in w95 (w95/w2000)

    Sorry- confusion now cleared up.

    Do you have the same version of Excel on you Win95 machine? Do you have a reference set to Excel from your Word VBA? Is it set to the correct version?
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  6. Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 opening excel in w95 (w95/w2000)

    I'm running Word 2000 on WinXP, and I could not get it to even compile.

    I added a reference to Excel. I did have to remove the call to "ClearTextBoxes" but that wasn't a big deal. But it didn't like the reference to <pre>Range("A3").CurrentRegion</pre>

    I had define it as an Excel range, otherwise it thought it was a Word object. I also had to move the definition of xlsApp to become a module level variable, and to use it in the Workbook activate event:

    [pre]
    Dim xlsApp As Excel.Application

    Private Sub imgSubmit_click()
    Dim wb As Workbook


    'code to make sure no other instance of excel is open

    'open the contact xls
    Set xlsApp = New Excel.Application
    'xlsApp.Visible = True
    xlsApp.Workbooks.Open FileName:="c:contacts.xls"
    Call AddToExcel
    ActiveWorkbook.Close SaveChanges:=True
    xlsApp.Quit
    Set xlsApp = Nothing
    ' Call ClearTextBoxes
    If MsgBox("Contact has been entered, do you want to enter another?", vbYesNo) = vbNo Then
    End
    End If

    End Sub

    Private Sub AddToExcel()

    Dim rngData As Excel.Range
    Dim rngRow As Excel.Range
    Dim lastRow As Integer

    xlsApp.Worksheets("Data").Activate
    Set rngData = Excel.Range("A3").CurrentRegion

    lastRow = rngData.Rows.Count + 1
    Excel.Range("A" & lastRow) = txtDate.Text

    End Sub
    [/url]
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  7. 4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 opening excel in w95 (w95/w2000)

    Thank you very much. I have a reference to excel 10.0 object library. I changed the code, see below. I still get a page fault error when i try it on a w95 box but i tested on both nt and w2000 and it works fine. Also, on the w95 box it does open excel but then i get a page fault error.

    dim xlsApp as excel.application
    private sub submit_click()
    dim wb as workbook

    set xlsApp = new Excel.Application
    xlsApp.Workbooks.Open filename:=App.Path & "contacts.xls"
    call addtoexcel

    if msgbox("enter another?", vbyesno) = vbno then
    activeworkbook.close saveChanges:=true
    xlsApp.quit
    set xlsApp = nothing
    end

    else
    call cleartextboxes
    end if
    end sub

    private sub addtoexcel()
    dim rngData as range
    dim rngRow as range
    dim lastRow as integer

    worksheets("Data").activate
    set rngData = xlsApp.Range("A3").currentregion
    lastRow = rngData.rows.Count + 1
    xlsApp.Range("A" & lastRow) = txtDate.text
    end sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •