User-defined type not defined - To Word

jagrenet

Board Regular
Joined
Feb 23, 2022
Messages
81
Office Version
  1. 365
  2. 2013
  3. 2011
  4. 2010
Platform
  1. Windows
Hello Gurus,

I have searched the Forum for the answer but, did not find anything matching my particular issue. Using VBA from Excel, I am creating a Word.Application to open a Word doc, copy the Paragraphs and paste them into Excel. Everything was working perfectly in my sandbox(testbed), without any problems at all.

When I decided the code was correct and ready for production, I moved it to a new Module. This is when I began getting "User-defined type" errors. I have checked, double checked and triple checked that all of the reference library's are added/loaded/referenced.(see attached image) They must be because this code worked flawlessly before I moved it.

Here are my Declarations -

Dim No_Of_Rows As Long
Dim No_Of_Columns As Long
Dim wd As Word.Application
Dim doc As Word.Document
Dim wr As Word.Range

Set wd = Word.Application
wd.Visible = True
wd.DisplayAlerts = wdAlertsNone

Set doc = wd.Documents.Open(OpenFile, False)
Set wr = doc.Paragraphs(1).Range
wr.WholeStory

While Stepping through the code, these Variables are the only problem that the Debugger does not like. Again, it's strange to me how it can work flawlessly one moment and then "out-of-nowhere" just decides it doesn't like my User-defined Variables.

Thanks in advance,
Jeff
 

Attachments

  • References.JPG
    References.JPG
    159.5 KB · Views: 11

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You have no reference to Word there. I imagine that you migrated this code to a different pc and forgot to set the reference.
Look at your first post & see what can happen to code that's not enclosed in vba code tags (vba button on posting toolbar).
Or did you put those emojis in there on purpose?
 
Upvote 0
You have no reference to Word there. I imagine that you migrated this code to a different pc and forgot to set the reference.
Look at your first post & see what can happen to code that's not enclosed in vba code tags (vba button on posting toolbar).
Or did you put those emojis in there on purpose?
LOL - I did not put those emojis in there - The post added them. Can you please clarify regarding the reference to Word? Isn't that reference covered in thhe "Microsoft Office 16.0 Object Library" that is selected? Or am I missing something else?
 
Upvote 0
No, it is not included.
AFAIK, that pertains to things that are common across all Office Apps. I think msoFileDialog would be an example of that.

1677787231758.png
 
Upvote 1
Solution
No, it is not included.
AFAIK, that pertains to things that are common across all Office Apps. I think msoFileDialog would be an example of that.

View attachment 86631
Feeling kinda dumb at this point. I assumed that since the code worked in the sandbox, it would work in the Module. You know what happens when we assume ...... - Thanks for pointing out the obvious. A tiny yet crucial oversight mistake on my part. Added the Microsoft Word reference .... issue corrected. Thank you Micron for jumping in to help !!
 
Upvote 0
NP. I don't think I've played in a sandbox since I was maybe 8 or so! Your experience is not familiar to me.
Thanks for the recognition.
 
Upvote 0
NP. I don't think I've played in a sandbox since I was maybe 8 or so! Your experience is not familiar to me.
Thanks for the recognition.
Just a colloquial term for testing environment (y)
 
Upvote 0
I know that. I guess I should ditch my plans to get into stand up comedy.
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top