Results 1 to 12 of 12

Thread: Still a problem

  1. #1

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Still a problem

    I had posted a problem with an automation error. Its been bugging me so I decided to play some more. This is an error when I m trying to save an excel file. If I do the following:

    Code:
    'turn on the hourglass
    'cause this could take some time...
    Screen.MousePointer = vbHourglass
    
    objXL.DisplayAlerts = False                      'don't show any alerts
    objXL.Visible = False                            'hide the sheet
    
    objXL.Application.ScreenUpdating = True          'allow updates
    
        If (WorkSheetExists(Me.txtTPos.Text, objXL)) Then
            'do nothing
            'sheet exists already so we just need to add the components
        Else
            'create the sheet
            Call CreateWorkSheet(Me.txtTPos.Text, objXL)
            objXLWrkBk.Save
        End If
    
    Call InsertComponents(Me.txtTPos.Text, objXL)    'now insert the components
        
        'objXLWrkBk.Close SaveChanges:=True               'save the changes
    objXL.Quit                                        'quit excel

    It quits the excel application but ASKS me if I want to save...I dont want it to ask me this. So I used the .DisplayAlerts and set it to false with no luck. Also I tried the one with the ' in front of it the:

    Code:
        'objXLWrkBk.Close SaveChanges:=True               'save the
    This used to work in my previous access application but it keeps giving me an automation error. So I had to comment it out. Basically I want to save this excel file and quit. But its not working!!!!

    Please help if possible.

    Jon

  2. #2
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    I think to avoid the Save dialog, you use the Save As method of the workbook to save it first. Then subsequent calls to Save use the same filename. If you haven't saved your workbook once, you need to call Save As one time, and pass it the path and File Name you want to save it as.
    ~seaweed

  3. #3

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by seaweed
    I think to avoid the Save dialog, you use the Save As method of the workbook to save it first. Then subsequent calls to Save use the same filename. If you haven't saved your workbook once, you need to call Save As one time, and pass it the path and File Name you want to save it as.

    In help:

    SaveAs Method


    Saves changes to the sheet (Syntax 1) or workbook (Syntax 2) in a different file.

    I dont want to save to a different file that is why I dont want saveas.

    Jon

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    So if it's an existing file then that's true, but if it's a new file then you need to do SaveAs first. From help:
    The first time you save a workbook, use the SaveAs method to specify a name for the file
    Is this an exisiting file you're working with? Then you should be able to do Workbook.Save
    ~seaweed

  5. #5

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Yes this is an existing file...I continue to get error messages with this:

    Class does not support automation or expected interface


    VB Code:
    1. Screen.MousePointer = vbHourglass
    2.  
    3. objXL.DisplayAlerts = False                      'don't show any alerts
    4. objXL.Visible = False                            'hide the sheet
    5.  
    6. objXL.Application.ScreenUpdating = True          'allow updates
    7.  
    8.     If (WorkSheetExists(Me.txtTPos.Text, objXL)) Then
    9.         'do nothing
    10.         'sheet exists already so we just need to add the components
    11.     Else
    12.         'create the sheet
    13.         Call CreateWorkSheet(Me.txtTPos.Text, objXL)
    14.         objXLWrkBk.Save
    15.     End If
    16.  
    17. Call InsertComponents(Me.txtTPos.Text, objXL)    'now insert the components
    18.    
    19.     objXLWrkBk.Save
    20.      'objXLWrkBk.Close SaveChanges:=True               'save the changes
    21.      objXL.Quit                                        'quit excel

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Wierd. My last suggestion is to try:
    VB Code:
    1. Dim objTmpWrkbk As Excel.Workbook
    2.    
    3.     For Each objTmpWrkbk In objXL.Workbooks
    4.         objTmpWrkbk.Save
    5.     Next
    6.     objXL.Quit
    but your error suggest something else might be wrong.
    ~seaweed

  7. #7

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Can I cuss on here?

    Cause ur faaaaaaarking awesome

    Thanks d00d

    Jon

  8. #8
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Glad it helped!
    ~seaweed

  9. #9

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Hey seaweed one other problem.
    I have a button to delete a sheet...after I delete it I save the excel file and quit. But everytime I try to delete...I get a message saying the selected cells have values are u sure you want to delete...
    I dont want this message...I just want it to delete:

    Heres the code:

    Code:
    Public Function DeleteCalcWorksheet(calcSheet As String, Pos As String)
    On Error GoTo Err_Handler
    'function deletes a work sheet in the calculation sheet
    'of Microsoft Excel.
    
    Dim objXL As Excel.Application
    Dim objXLWrkBk As Excel.Workbook
    Dim objXLWrkSht As Excel.Worksheet
    
    Set objXL = CreateObject("Excel.Application")
    objXL.Visible = False
    objXL.DisplayAlerts = False
    Set objXLWrkBk = objXL.Workbooks.Open(calcSheet)
        
    If (WorkSheetExists(Pos, objXL)) Then
        Set objXLWrkSht = objXLWrkBk.Worksheets(Pos)
        objXLWrkSht.Delete
        objXLWrkBk.Close SaveChanges:=True
        objXL.Quit
    Else
        'work sheet not found
        'do nothing
    End If
    
    Done:
    Set objXLWrkSht = Nothing
    Set objXLWrkBk = Nothing
    Set objXL = Nothing
    Exit Function
    
    Err_Handler:
    MsgBox Err.Description, vbCritical, "Error #: " & Err.Number
    Resume Done
        
    
    End Function
    thanlks jon

  10. #10
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Setting DisplayAlerts to False should take care of it, but it looks like you are doing that already. You might try setting it again just before the call and see if that helps(?).
    ~seaweed

  11. #11

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Tried that no luck

  12. #12

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    This is weird now its working...
    Tomorrow it wont...
    Well C how it goes.

    Thanks,
    Jon

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