• Revisit: Error during pasting (Office 2003)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Revisit: Error during pasting (Office 2003)

    Author
    Topic
    #432410

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1014322

      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?

      • #1014325

        1. It was not declared anywhere else.

        2. Word is running at all time.

        Cheers
        Ridz

        • #1014328

          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.

          • #1014331

            Thanks Hans,

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

            Regards
            Ridz

            • #1014334

              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?

            • #1014354

              clapping

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

              Thank you Hans.

            • #1014355

              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.

    Viewing 0 reply threads
    Reply To: Revisit: Error during pasting (Office 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: