Dim Objword As Word.application Error
Contents |
help? Post your question and get tips & solutions from a community of 418,493 IT Pros dim wdapp as word.application user defined type not defined & Developers. It's quick & easy. Dim objDoc As Word.Document isn't working! microsoft word 12.0 object library dll download P: 3 jfarley I have been searching everywhere to try to figure out how to use Access
User Defined Type Not Defined Word Vba
to open an existing Word document that is merged to an Excel spreadsheet and merge the data when it opens. I'm working with two different version, Word 2000 and
Microsoft Word 12.0 Object Library Download
2003. I got it to work perfect in 2000, but when I use it in 2003, the Word document opens and it is not linked to a data source. The closest thing I have found to help me out is a function written on this site called MergeIt(), but when I compile, this line, "Dim objDoc As vba tools references greyed out Word.Document," gives me this error: Compile error: User-defined type not defined. What am I doing wrong? Any help is GREATLY appreciated. I have already spent way too much time on trying to figure this one out. Here is the code I'm trying to use: Function MergeIt() On Error GoTo ErrHandling Dim objDoc As Word.Document Dim objWord As Word.Application Dim blnCreated As Boolean Dim strFilename As String Dim strQueryName As String Dim strDBpath As String strFilename = "e:\SUMMONSFORM.DOC" strQueryName = "qryOWNERCODEFENDANTsummonsmergedata" strDBpath = "E:\CityTaxSaleV63.mdb" 'Or probably just CurrentDb.Name On Error Resume Next Set objWord = GetObject(, "Word.Application") If Err Then Set objWord = CreateObject("Word.Application") blnCreated = True End If On Error GoTo ErrHandling Set objDoc = objWord.Documents.Open(strFilename) 'Make Word Visible objWord.Visible = True 'Execute the MailMerge With objDoc.MailMerge 'Set Merge Data Source objDoc.MailMerge.OpenDataSource Name:=strDBpath, _ LinktoSource:=True, _ Connection:="QUERY " & strQueryName, _ SQLStatement:="SELECT * FROM " & strQueryName .Destination = wdSendToNewDocument .Execute objWord.ActiveDocument.PrintOut False objWord.ActiveDocument.Close wdDoNotSaveChanges End With 'Close The form files and the merged document objDoc.Close wdDoNotSaveChanges If blnCreated Then objWord
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow
Vba Tools References Disabled
the company Business Learn more about hiring developers or posting ads with us Stack microsoft word object library Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of vba open word document 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Close/Release Word object in VBA? up vote 3 down vote favorite I have the following code to https://bytes.com/topic/access/answers/626840-dim-objdoc-word-document-isnt-working open the manual for an Excel Workbook application I have developed: Sub OpenManual() 'Word.Application.Documents.Open "\\filePath\FormFlow To MSExcel\FeedSampleReport-Manual.docx" Dim objWord As Object Set objWord = CreateObject("Word.Application") objWord.Visible = True objWord.Documents.Open "\\filePath\FormFlow To MSExcel\FeedSampleReport-Manual.docx" End Sub This gives me 2 issues though: The document opens, but in the background. The user doesn't know the document has opened unless they know to check Microsoft Word in the Taskbar. When I try to close the word http://stackoverflow.com/questions/17177412/close-release-word-object-in-vba document I receive: This file is in use by another application or user. (C:\Users\Me\AppData...\Normal.dotm) When I click ok on that dialogue, I receive a "Save As" screen. If I cancel out of that and try to close the blank Microsoft Word instance I then get: Changes have been made that affect the global template, Normal. Do you want to save those changes? Then if I click No, everything finally closes. Can anyone help me out with these 2 issues? Do I need to release the object somehow? Have never seen this before. EDIT: After trying @Layman-Coders method: Sub OpenManual() 'Word.Application.Documents.Open "\\filePath\FormFlow To MSExcel\FeedSampleReport-Manual.docx" 'Open an existing Word Document from Excel Dim objWord As Object Set objWord = CreateObject("Word.Application") objWord.Visible = True ' Should open as the forefront objWord.Activate 'Change the directory path and file name to the location 'of the document you want to open from Excel objWord.Documents.Open "\\filePath\FormFlow To MSExcel\FeedSampleReport-Manual.docx" objWord.Quit Set objWord = Nothing End Sub When I have one other word document open and click the button, the following occurs: Manual opens in the forefront, but I immediately receive This file is in use by another application or user. (C:\Users\Me\AppData\...\Normal.dotm) I press OK and receive the Save As dialogue. Cancel out of the Save As dialogue and am presented my M
soon) Ruby (coming soon) Getting Started Code Samples Resources Patterns and Practices App Registration Tool Events Podcasts Training API Sandbox Videos Documentation Office https://social.msdn.microsoft.com/Forums/office/en-US/79a997cd-8352-4e2e-b0f7-b24462c89bd2/compile-error-userdefined-type-not-defined?forum=accessdev Add-ins Office Add-in Availability Office Add-ins Changelog Microsoft Graph API Office 365 Connectors Office 365 REST APIs SharePoint Add-ins Office UI Fabric Submit to the Office Store All Documentation http://www.vbaexpress.com/forum/archive/index.php/t-31950.html https://www.yammer.com/ http://feeds.feedburner.com/office/fmNx Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Answered by: Compile Error: User-defined type not defined Microsoft microsoft word Office for Developers > Access for Developers Question 0 Sign in to vote Hello all I'm trying to do a mail merge into Word. When I click on the button I'm getting the a Compile Error Please see the code below. Private Sub MailMergeButton_Click() On Error GoTo Err_MailMergeButton_Click Dim objwordApp As Word.Application Dim objWordDoc As user defined type Word.Document If AddressAlocationType = 3 Then Exit Sub Set objwordApp = CreateObject("objword.application") wordApp.Visible = True Select Case [AddressAlocationType] Case 1 Set objWordDoc = wordApp.Documents.Add("c:\database\W_L_G.dot") Case 2 Set objWordDoc = wordApp.Documents.Add("c:\database\W_L_P.dot") Case 3 Exit Sub End Select Exit_MailMergeButton_Click: Exit Sub Err_MailMergeButton_Click: MsgBox Err.Description Resume Exit_MailMergeButton_Click End Sub Can someone be so kind to let me know what I'm doing wrong... Many thanks Thursday, November 10, 2011 1:04 PM Reply | Quote Answers 1 Sign in to vote You need to go in VBE windows, then menu Tools > References > then search for Microsoft Word xx.0 Object Library The xx is a Number, which can vary depending on which version of Office you have installed. To make use of the Word Object Library, you must have installed Word on your PC, I assume you have. You might use Late binding, to avoid using Word Object Library, but thats another
reads an xls file and writes a Word Document. I now have a slightly more complicated Word document to create from one of my xls files; I need to write some boiler plate lines and paragraphs, then, I need to build the manuscript for a Table of Contents page. My challenge comes in trying to set the tab stops. When I record a macro in Word, I have no problem, I can record the macro and I can run the macro, all is well. However, when I copy that part of the macro in to the code for Excel to run it, Excel chokes on the following, giving me a "Compile Error: Sub or Function not defined" and the first instance of 'InchesToPoints' is highlighted. Set wrdDoc = oWDBasic.Documents.Add oWDBasic.Visible = True 'add text to top of doc and spaces before table oWDBasic.ActiveDocument.Select With oWDBasic.Selection Selection.ParagraphFormat.TabStops.ClearAll ActiveDocument.DefaultTabStop = InchesToPoints(0.5) Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(5.58), _ Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(6.13), _ Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces Selection.Font.Name = "Arial" End With How do I work my way around this? Is there a service pack I have to install? Is there a way from within Excel to set the Word tab stops? Do I need to create a function (naming it InchesToPoints) that turns 1 inch into X points (where X is probably 12pt/in), doing the math to convert each measurement? Or, do I have to build my table of contents as a Word Table loading the cells in Word from the cells in Excel? Thanks! fumei05-05-2010, 01:02 PMAre you using early binding? I notice you seem to be using Dim ObjWord As Object rather than Dim ObjWord As Word.Application If so, then it does not know what InchesToPoint means (more specifically "Sub or Function not defined"). InchesToPoint is a Function (not a property). RonMcK305-05-2010, 01:34 PMGerry, Let me make that change and see how that helps me. Thanks! fumei05-05-2010, 01:35 PMTo use early binding you have to have a Reference. Do you? RonMcK305-05-2010, 01:42 PMGerry, Here is the code from the beginning down to the point I showed before. I believe that I invoke word with the following: Set oWDBasic = CreateObject("Word.Application") So, is this early or late binding? Thanks, Ron Sub XLToWordTable2a() Dim ObjWord As Object, Rng As Range Dim wrdDoc As Object, Ocell As Variant, TC As Variant Dim LastRow As Long, LastCol As Long, Cnt As Long Dim FirstRow As Long, FirstCol As Long Dim Grade As Int