Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2016, 07:49 AM
brynrogers brynrogers is offline Word.Application Object Windows 7 64bit Word.Application Object Office 2013
Novice
Word.Application Object
 
Join Date: Nov 2016
Posts: 2
brynrogers is on a distinguished road
Default Word.Application Object

Hello,

I'm new to this forum, and this isnt strictly a VBA question more a VBS one but it is relevant so please hear me out.

Im trying to run this piece of code..

Set oWord = CreateObject("Word.Application")

oWord.AddIns.Add FileName:="C:\Program Files (x86)\Labelling Tool v.2.0\LabelingData\Labeling.dotm", Install=True


oWord.AddIns ("Labeling.dotm").Installed = True

oWord.Quit

Set oWord = Nothing

However it stop at this line..

oWord.AddIns.Add FileName:="C:\Program Files (x86)\Labelling Tool v.2.0\LabelingData\Labeling.dotm", Install=True


With this error..
Microsoft VBScript compilation error: Expected statement

The file does exist in this location.

If I comment this line out, (the addon is already installed), I get an error on the next line...

'The requested member of the collection does not exist'
Its referring to 'Labeling.dotm'

I have followed the API info for these methods and properties, and yet they just dont work?

Can anyone help please?

Thanks, brynrogers
Reply With Quote
  #2  
Old 11-10-2016, 08:29 AM
brynrogers brynrogers is offline Word.Application Object Windows 7 64bit Word.Application Object Office 2013
Novice
Word.Application Object
 
Join Date: Nov 2016
Posts: 2
brynrogers is on a distinguished road
Default

OK I see the errors of my ways now... this works without error.. but the AddIn is still not enabled?

Set oWord = CreateObject("Word.Application")
Set oAddins = oWord.AddIns

oAddIns.Add "C:\Program Files (x86)\Labelling Tool v.2.0\LabelingData\Labeling.dotm", True
oAddIns ("C:\Program Files (x86)\Labelling Tool v.2.0\LabelingData\Labeling.dotm").Installed = True

Set oAddins = Nothing
oWord.Quit
Set oWord = Nothing
Reply With Quote
  #3  
Old 11-10-2016, 04:17 PM
Guessed's Avatar
Guessed Guessed is offline Word.Application Object Windows 10 Word.Application Object Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Your code is doing as you expect but you are not making use of the loaded addin before quitting Word. If Word is subsequently re-opened, you will discover the addin is now in your list of addins but its status is not turned on.

You can either choose to turn this on every time you open Word by using just your .Installed line but if you want it ALWAYS turned on, it is easier to simply copy the template to the Addins folder.

By default the Addins folder is in %appdata%\Microsoft\Addins OR %appdata%\Microsoft\Word\STARTUP but it could have been changed by the user so this following code would perform the task of installing the template in a location so that whenever Word is opened, the addin is installed and active.

Code:
Set oWord = CreateObject("Word.Application")
  Dim sAddins As String
  sAddins = oWord.Options.DefaultFilePath(8) 'where 8 = wdStartupPath
  FileCopy "C:\Program Files (x86)\Labelling Tool v.2.0\LabelingData\Labeling.dotm"", sAddins & "\Labeling.dotm"
  oWord.Quit
Set oWord = Nothing
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word.Application Object cannot start the source application for this object - Excel charlesmac Excel 3 08-15-2012 05:22 AM
Word.Application Object Range.Information(wdStartOfRangeRowNumber): Application-defined or Object-defined err tinfanide Excel Programming 2 06-09-2012 10:19 AM
Word.Application Object Application-defined or Object-defined error Manit Excel Programming 4 12-08-2011 07:35 PM
Word.Application Object A word macro application Hikmetotheron Word 3 04-26-2011 02:01 PM
Problem with my microsoft word com object in c# web application Naresh_1210 Word VBA 0 03-11-2010 12:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft