+ Reply to Thread
Results 1 to 5 of 5

VBA error - type mismatch

  1. #1
    Registered User
    Join Date
    11-17-2023
    Location
    Toronto
    MS-Off Ver
    MS office 365
    Posts
    3

    VBA error - type mismatch

    see the error and code in the attached file.
    you could see the code below as well.
    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Our guidelines recommend code tags. I have added them for you this time because you are a new member. --6StringJazzer

    Dollygg screenshot.jpg
    Attached Files Attached Files
    Last edited by 6StringJazzer; 11-17-2023 at 11:26 PM. Reason: please use code tags

  2. #2
    Registered User
    Join Date
    11-17-2023
    Location
    Toronto
    MS-Off Ver
    MS office 365
    Posts
    3

    Re: VBA error - type mismatch

    thanks for adding the code tag!

  3. #3
    Registered User
    Join Date
    11-17-2023
    Location
    Toronto
    MS-Off Ver
    MS office 365
    Posts
    3

    Re: VBA error - type mismatch

    actually the VBA code works in Word !!

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA error - type mismatch

    Please don't attach files with screenshots, just upload them inline. I have edited your post to do so.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: VBA error - type mismatch

    First, and most important, you should use Option Explicit and declare variables. Doing so prevents a lot of bugs and runtime errors.

    The problem you are having is that Word has an object called a Range, and Excel has an object called a Range. They are completely different but you are trying to assign one to the other, so you get a type mismatch.

    Please Login or Register  to view this content.
    When you run this code in Excel, Excel assumes this is an Excel Range. From context, I think you want it to be a Word Range. Change the declaration to this:
    Please Login or Register  to view this content.
    Your code works in Word because Range is assumed to be a Word Range when you are running this code under Word.

    I can't do any testing without an example Word file to go with this code, but I'm pretty sure this will fix your problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] UBound coll error after converting macro. Runtime error 13. Type mismatch.
    By Elijah in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-30-2020, 05:08 AM
  2. [SOLVED] RunTime Error 13 ( type mismatch ) error is comming TextboxAfter_Update
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2017, 03:55 AM
  3. Run Type error 13 Type Mismatch
    By Affan Khan in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-13-2012, 12:58 PM
  4. [SOLVED] Run-type error 13 type mismatch
    By misop in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-05-2012, 04:08 AM
  5. Complile Error: Type Mismatch ??? After adding error trap
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2012, 03:50 PM
  6. Conditional Formatting - Run Time Error '13' Type Mismatch Error
    By ksp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-17-2011, 07:37 PM
  7. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1