Results 1 to 11 of 11

Thread: Saving Cause Runtime Error

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Saving Cause Runtime Error

    Hi,

    I have a fairly large xl file with plenty of macros (2mb). What I can not figure out is when I save my workbook to a different name using the 'save as' option, I get runtime errors.

    First one is it complains about the scroll column proprety I use:
    VB Code:
    1. With ActiveWindow
    2.     .ScrollColumn = incrcol
    3.     .ScrollRow = 1
    4. End With

    I am assuming when I save my workbook in a different name, the activewindow changes? Is there another way around this?

    Second error I get is 'unable to get chart object' from below:
    VB Code:
    1. Sheets(currentsheetname).ChartObjects(1).Activate
    I get this error for every chart object in my worksheet. Why can't I access it if I save my workbook to another name?

    Any help will be greatly appreciated thanks!!

  2. #2
    Lively Member JustinLabenne's Avatar
    Join Date
    Jul 2005
    Location
    Ohio
    Posts
    64

    Re: Saving Cause Runtime Error

    Sounds like you have some event codes that run when your saving the file. When you look in the THisWorkbook module, do you have any BeforeSave events?
    Justin Labenne
    www.jlxl.net

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Re: Saving Cause Runtime Error

    How do I prevent these events from running when I save? I do have some events such as worksheet_activate, workbook_open, button_click events, etc.

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Re: Saving Cause Runtime Error

    btw,

    I have two worksheets that do similar tasks of activating charts and scrolling. I noticed when I save my workbook as another name, the error occurs in the other sheet, and vice versa if my activesheet was the other sheet.

    Is there some sort of linkage when I save my workbook using the 'save as' option with other sheets? So confused...

  5. #5
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Saving Cause Runtime Error

    You have a number of choices:

    1. Delete all of the event handling routines - not recommended
    2. Turn off events using Application.EnableEvents = False
    3. Comment out selected event handlers w/ ':

    VB Code:
    1. 'Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
    2.         ByVal SaveAsUI As Boolean, Cancel as Boolean)
    3.     'a = MsgBox("Do you really want to save the workbook?", vbYesNo)
    4.     'If a = vbNo Then Cancel = True
    5. 'End Sub

    VBAhack

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Re: Saving Cause Runtime Error

    Thanks for the helpful tips.
    Well I shouldn't do the first one because then my whole sheet would not work.
    I tried using the enableevents property, setting that to false.

    I get different errors when I do that:

    VB Code:
    1. ' runtime error: unable to set Characters Property  of Title
    2. with activechart
    3. .title.characters.text = "chart title"
    4. end with

    Also, I do not have an event handling beforesave, so option 3 probably wouldn't work. Unless you feel adding a beforesave event would work better then can you elaborate on it more? Thanks!

  7. #7
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Saving Cause Runtime Error

    No WorkbookBeforeSave, eh? Quite a mystery you have, my friend. It was a logical choice (like JustinLabenne suggested in an earlier post) since the errors only occur when you perform a 'Save As'. Hmmmmm, well one other possibility is to print out a msgbox in each event code to see which one fires last before you get the error. Kind of tedious, but no other suggestion comes to mind. It means putting something like the following at the beginning of each event handler:

    VB Code:
    1. Msgbox "This is xxx"

    Where xxx is the name of the event handler. The last one to post before the error message occurs would be the first place to look. This assumes an event handler is the cause. Sorry, can't think of anything else. Maybe others can think of something.

    VBAhack

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Re: Saving Cause Runtime Error

    Ok, I figured out what event is being called when I use the save as option.

    Currently I have two sheets which consists of 10 embedded charts on each page. They both contain the same vba logic, but plot different data.

    On each sheet, each chart has 10 associated comboboxes where the user can click which data to plot ( which are located on the same sheet).

    If I am in one sheet, the combobox's events located in the OTHER sheet is called, i.e. select_change event. In each event, I activate the chart, which is specifically where the runtime error occurs. Why would the select change event for comboboxes be ran after I save my workbook in another name?

  9. #9
    Lively Member JustinLabenne's Avatar
    Join Date
    Jul 2005
    Location
    Ohio
    Posts
    64

    Re: Saving Cause Runtime Error

    Can you attach a sample of your workbook here? It may be a question of minor corruption in the workbook (possible, lots of charts, event handlers galore). That is worst case, it sounds like the charts or something within the code may be hard coded and referencing the old file name for some reason.

    Best bet, attach a sample, or post oodles of your code on the board. A sample would be loads easier for people to help with though...........
    Justin Labenne
    www.jlxl.net

  10. #10

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Talking Re: Saving Cause Runtime Error

    Hi,

    because of the size quota, I was wondering if I can just email you my workbook. Posting parts of my code might be a little confusing since you will not get the general idea of what is goign on. It will be greatly appreciated if you can see what is going on in my code. I want to get your permission first before I email it to you.

  11. #11

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    42

    Re: Saving Cause Runtime Error

    Hi,

    I actually fixed problem. I just added a flag so some of the events will not run at certain times. Thanks anyways!

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