+ Reply to Thread
Results 1 to 12 of 12

Passing variable to Word BYRef argument Type Mismatch

  1. #1
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Passing variable to Word BYRef argument Type Mismatch

    Im trying to pass data from an Excel sheet to a Word doc, I've created the most basic of test code but no matter what I try I always get the same "ByRef Argument Type Mismatch" error.
    In Excel
    Please Login or Register  to view this content.

    While the Word doc has
    Please Login or Register  to view this content.
    I've tried adding ByRef, ByVal etc but always the same error

    Anyone tell me what Im doing ridiculously wrong?
    If someone has helped you then please add to their Reputation

  2. #2
    Registered User
    Join Date
    09-25-2012
    Location
    GER
    MS-Off Ver
    365
    Posts
    3

    Re: Passing variable to Word BYRef argument Type Mismatch

    Hi pjwhitfield,
    Are you running your subs on module level? If not, try so and tra using a function in your .docm file, and try to declare your Excel sub public instead.
    //EarlyBird2

  3. #3
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Passing variable to Word BYRef argument Type Mismatch

    Your code works properly for me. Are you sure you don't have another test routine that is being called?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  4. #4
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Passing variable to Word BYRef argument Type Mismatch

    Thanks for the posts folks,

    As per EarlyBirds thoughts I've tried moving the code to a module...same issue, I've then tried changing to a Function (both in Module and Document)...same issue.

    As xlnitwit was saying the code worked I then decided to put the Word code into a new blank document and yes it worked fine.

    So the issue would appear to be in the Word doc that Im amending, unfortunately Im unable to upload it as its a business sensitive document, has anyone got any ideas what else could cause this?

    There is no other VBA in the document however there is a Reference shown within VBA to another document however I cant access any code via my document and when I open the referenced doc theres no VBA there either?

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Passing variable to Word BYRef argument Type Mismatch

    If you change the name of the routine and arguments to something else, does it make any difference?

  6. #6
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Passing variable to Word BYRef argument Type Mismatch

    Nope, I changed the routine (in the Word doc) to "sausages" and the argument to "PorkData"

    safe to say that, unless the document Im working on is from Richmonds Sausages Ltd then chances are those names dont exist elsewhere.

    Same error.

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Passing variable to Word BYRef argument Type Mismatch

    Do you actually need to pass it ByRef? Does the error go away if you use
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Passing variable to Word BYRef argument Type Mismatch

    No, the only reason ive tried adding ByRef was because I was getting the error, ive tried ByRef, ByVal and just the straight variable both with and without the "As String".

    Everything gives the same error message.

    I think this may require the word document to be recreated and try from there. Its just bugging me when I cant see a reason for the problem.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Passing variable to Word BYRef argument Type Mismatch

    What happens if you comment out the Run line completely?

  10. #10
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Passing variable to Word BYRef argument Type Mismatch

    The Word doc opens as expected, no errors raised.

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Passing variable to Word BYRef argument Type Mismatch

    I'd have to see the document then (you could remove all data). There is no reason that an argument passed ByVal should ever cause a ByRef mismatch.

  12. #12
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Passing variable to Word BYRef argument Type Mismatch

    I think the issue is the fact this document was originally produced from a central template which is the document thats mentioned in Document References. I cant see any way to remove that reference. I've tried through Properties>Remove Properties but that states it cant be done as the document is "open in COM Surrogate" (my doc isnt open so it must be referring to the template doc).

    I have now recreated the document from scratch and its working fine.

    Would be nice to understand exactly what the issue was because it definitely couldn't be conflicting Sub or Data names.

    xlnitwit, the data in the doc is very secure so technically I'd have to remove everything from it leaving a blank doc (well i could probably leave the header in).

+ 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] ByRef Argument Type Mismatch Error
    By ALEXJM in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-03-2017, 11:06 AM
  2. ByRef argument type mismatch
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2015, 11:23 AM
  3. ByRef argument type mismatch vs variable declaration
    By Dturazza in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2013, 09:06 AM
  4. [SOLVED] ByRef argument type mismatch
    By Lloyd Blankfein in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-06-2012, 07:26 AM
  5. [SOLVED] ByRef argument type mismatch / Passing array as a function argument
    By pzling in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2012, 06:23 PM
  6. Byref argument type mismatch
    By ref in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2012, 06:17 AM
  7. Error passing element of string array get ByRef argument type mismatch
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-17-2011, 02:59 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