Results 1 to 4 of 4

Thread: WkS.Copy behaves buggy when put online

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257

    WkS.Copy behaves buggy when put online

    Hello,

    My Excel 97/VBA is executed online from a web server.
    Two things are wrong with my Save Routine:

    1. I do a Worksheet.Copy, Save it, Close it, and Retun to ThisWorkbook.
    The problem is after this executes there is a big empty Window named "Microsoft Excel [Read-only]" which has the focus. My guess is that a new window is opened to create a new Workbook, then copies the Worksheet in. After Saving & Closing, only the empty window is left. If I close this empty window, my Application stops. My Application is running in a separate Window.

    2. In the debugger, I see that "Application.ScreenUpdating = False" never gets set to False. Odd!

    Here is the Save Routine:
    VB Code:
    1. Private Sub cmdSave_Click()
    2.  Dim varFileName As Variant
    3.  
    4.  On Error GoTo 300
    5.  ChDir "C:\"
    6.  Do
    7.  varFileName = Application.GetSaveAsFilename("My Report", "Excel File(*.xls),*.xls", , "Save My Report")
    8.  Loop Until varFileName <> False
    9.  If (VarType(varFileName) = vbString) Then
    10.    Application.ScreenUpdating = False
    11.    objMyWS.Copy
    12.    ActiveWorkbook.SaveAs FileName:=varFileName, FileFormat:=xlWorkbookNormal
    13.    ActiveWorkbook.Close savechanges:=False
    14.    ThisWorkbook.Activate
    15.    Application.ScreenUpdating = True
    16.  End If
    17.    objMyWS.Activate
    18.    Exit Sub
    19. 300:
    20.    MsgBox Err.Number & " " & Err.Description
    21.    Resume Next
    22. End Sub
    The question is, How do I remove the big empty Window and stop it from receiving focus? I would like that window to go away after the Workbook is closed. Why does "ScreenUpdating = False" fail? I need the WkSheet to refresh itself after line deletion (in another section of code).

    It works fine offline, but once online - all rules change.

    TIA,CJ

  2. #2
    Addicted Member
    Join Date
    Dec 2001
    Posts
    158
    Are you opening another workbook?
    If so have you thought about reading the other workbook(sheet) like a db without opening it?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257
    Hello,

    I am opening a new Workbook to save my current Worksheet into.

    Could I do something tricky to get the Worksheet's data into the new Workbook? - like use it as a db? How would that work?

    CJ

  4. #4
    Addicted Member
    Join Date
    Dec 2001
    Posts
    158
    You can use a closed workbook just like a database. You have to make a reference to MS ActiveX DataObjects (ver x.x).
    info:
    http://www.exceltip.com/show_tip/Imp...as_a_database_(ADO)_using_VBA_in_Microsoft_Excel/432.html

    Try this search on Google for more examples: "Use a closed workbook"

    Besides the ADO/SQL stuff, you can reference ranges and cells in a closed workbook directly: http://www.rondebruin.nl/ado.htm



    I'm guessing you have Excel setup to open new workbooks in a different (new) Excel process (/window) which might also explain why the screenupdating is not working.

    If that is the case you might try this (I'm guessing - never used it):
    ActiveWindow.Application.ScreenUpdating = False

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