Results 1 to 8 of 8
  1. #1
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Revisit: Error during pasting (Office 2003)

    Dear All,

    Attached file contains code to resize charts, paste into new Word document. Hans helped me fixed the codes sometimes in Dec 05. Again, it worked fine until today. I got Runtime Error 13: Type Mismatch at "Set wordFile = appWord.Documents.Add". Can anyone help and try to explain why it worked then but not now?

    Thank you in advance.
    Ridz

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Revisit: Error during pasting (Office 2003)

    1) The variable wordFile is not declared in the code you posted. Is it declared elsewhere?

    2) The code assumes that Word is already running. Is that always the case?

  3. #3
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Revisit: Error during pasting (Office 2003)

    1. It was not declared anywhere else.

    2. Word is running at all time.

    Cheers
    Ridz

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Revisit: Error during pasting (Office 2003)

    Try declaring wordFile at the beginning of the PasteToNewWordFile procedure:

    Dim wordFile As Word.Document

    Also, near the end of the procedure, you have

    Set fileWord = Nothing

    This should be

    Set wordFile = Nothing

    Note: apparently, you do not require variable declaration, otherwise, VBA would have warned you about this inconsistency. I strongly recommend the following:

    1) In the Visual Basic Editor, select Tools | Options..., activate the Editor tab (if necessary) and tick the "Require variable declaration" check box.
    This will add a line Option Explicit at the top of each new module you create.
    2) Insert the line Option Explicit manually at the top of existing modules.

    Although the error messages you get about "Variable not defined" will be irritating initially, it will save you a lot of grief in the long run.

  5. #5
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Revisit: Error during pasting (Office 2003)

    Thanks Hans,

    I did as suggested (declaration and set the Options). But now I bumped into Error 424 at the same line.

    Regards
    Ridz

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Revisit: Error during pasting (Office 2003)

    Apparently, the appWord object is not valid when code execution arrives at that line. The code itself is OK: it runs fine when I try it. So there must be something else. Does the error persist if you quit Word and Excel and start anew, or if you restart your PC?

  7. #7
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Revisit: Error during pasting (Office 2003)

    <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>

    How on earth do you know that I need to restart the PC?

    Thank you Hans.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Revisit: Error during pasting (Office 2003)

    Since the code itself was correct, the most plausible explanation for the problem was that something in your computer's memory had gone awry. Restarting the PC clears the memory.

    In general, restarting a PC is a good idea if you run into otherwise inexplainable errors.

Posting Permissions

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