CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: saving to excel

  1. #1
    Join Date
    Mar 2001
    Posts
    67

    saving to excel

    I use the following vb code to save data in an msflexgrid to an excel file,together with a common dialogue box, cdsave to select the excel file to save to. However i seem to encounter two dialogue boxes, one from the cdsave dialogue box i created and the other an unknown dialogue box. The second dialogue box comes together with this message: "A file named "resume.xlw" already exists in this location.Do u want to replace it?"

    How do I remove this second dialogue box together with its message?

    My code is as follows:
    private Sub mnufilesaveData_Click()
    Call frmchoice.Show(vbModal, me)


    Dim obExcelApp as Object
    Dim obworksheet as Object
    Dim blnrunning as Boolean
    Dim intCtr as Integer
    Dim intcell as Integer
    Dim teststring as string
    Dim intFnum as Integer


    If (filetype = 1) then

    'cdsave.filter = "excel(*.xls)|*.xls"
    'cdsave.ShowSave


    on error resume next

    set obExcelApp = GetObject(, "Excel.application")
    If Err.Number <> 0 then

    set obExcelApp = CreateObject("Excel.application")
    blnrunning = false

    else
    blnrunning = true
    End If

    obExcelApp.Workbooks.Add

    set obworksheet = obExcelApp.ActiveSheet

    'Enter values in active sheet's cells

    obworksheet.cells(1, 1).value = "Location"
    obworksheet.cells(1, 2).value = " Max Received signals"
    obworksheet.cells(1, 4).value = "Received signals"
    obworksheet.cells(1, 6).value = " Min Received signals"
    obworksheet.cells(1, 8).value = "Simulated signals"


    obworksheet.cells(1, 2).WordWrap true
    obworksheet.cells(1, 4).WordWrap true
    obworksheet.cells(1, 6).WordWrap true
    obworksheet.cells(1, 8).WordWrap true


    for intCtr = 0 to num_of_locations

    intcell = intCtr + 2
    obworksheet.cells(intcell, 1).value = Generated.strlocation(intCtr)
    obworksheet.cells(intcell, 2).value = Generated.dblMaxPower(intCtr)
    obworksheet.cells(intcell, 4).value = Generated.dblMeanPower(intCtr)
    obworksheet.cells(intcell, 6).value = Generated.dblMinPower(intCtr)
    obworksheet.cells(intcell, 8).value = dblStr_received(intCtr)

    next intCtr

    'obExcelApp.DisplayAlerts = false
    obExcelApp.Save

    obExcelApp.ActiveWorkbook.Close false

    If Not (blnrunning) then
    obExcelApp.Quit
    End If




    I would also like to have the option of either writing to a text file or excel file. Currently I call up another form for the user to select. Is there any other way to do the selection using the cdsave common dialogue box?




  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: saving to excel

    You can suppress alerts. Program will be saved without asking

    xlapp.displayalerts = false


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured