Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.



1966 posts

Uber Geek

Subscriber

Topic # 104707 20-Jun-2012 17:20 Send private message

I'm trying to put together a template file that when loaded into Word (2010) via startup, will add a custom tab to the ribbon with some shortcuts to open a selection of templates at a fixed location. I can't for the life of me work out how to get Word to actually open a file via a macro command.

The VBA script I'm trying to use is:

Sub OpenFile1()
Dim wdApp as Object
Set wdApp = CreateObject("Word.Application")  - Probably redundant, makes no difference
wdApp.Visible = True
wdApp.Documents.Open Filename:="Filepath+name"
End Sub

The CustomUI.xml code that I'm trying to call it with is:

<button id="button1" label="Open File" size="normal" imageMso="Image" onAction="OpenFile1" />

Any ideas what I'm doing wrong?

I'm trying to make this fairly portable so we can give it to a few people so they've got a quick & simple way of getting at the right set of templates.  It looks like it should be fairly easy, but I just get an "invalid property assignment" error.





"You are" = "You're" - Not "Your".  "They are" = "They're" - Not "Their" or "There".  You probably mean "lose" not "loose".  There's no such word as "Alot".
 
On the internet, wasting time, since '89.

Create new topic

gzt

3244 posts

Uber Geek

Subscriber

  Reply # 644056 20-Jun-2012 22:34 Send private message

does your vba script work by itself?



1966 posts

Uber Geek

Subscriber

  Reply # 644159 21-Jun-2012 10:28 Send private message

It works by itself, so I must be calling it incorrectly in the CustomUI code.




"You are" = "You're" - Not "Your".  "They are" = "They're" - Not "Their" or "There".  You probably mean "lose" not "loose".  There's no such word as "Alot".
 
On the internet, wasting time, since '89.



1966 posts

Uber Geek

Subscriber

  Reply # 644178 21-Jun-2012 11:14 Send private message

It worked when I added a separate function as a "control" and called the actual open function from that:

Sub OpenFile2()
Dim wdApp As Object
Dim wdDoc As Object
Dim sFname As String
sFname = "C:\Templates\Doc1.docx"
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add(sFname)
End Sub

Sub BtnPress(control As IRibbonControl)
Call OpenFile2
End Sub


Now I just need to tidy things up and I should be able to get a nice tidy menu system going.




"You are" = "You're" - Not "Your".  "They are" = "They're" - Not "Their" or "There".  You probably mean "lose" not "loose".  There's no such word as "Alot".
 
On the internet, wasting time, since '89.

Create new topic





Twitter »
Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when new jobs are posted to our jobs board:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:




News »

Trending now »
Hot discussions in our forums right now:

Sky outbid for EPL rights (Premier League Pass discussion)
Created by JonnyCam, last reply by Benoire on 19-Jun-2013 23:03 (234 replies)
Pages... 14 15 16


Slingshot Global Mode announced
Created by freitasm, last reply by driller2000 on 19-Jun-2013 23:38 (47 replies)
Pages... 2 3 4


Orcon Genius Go discussion
Created by freitasm, last reply by ptinson on 19-Jun-2013 21:22 (46 replies)
Pages... 2 3 4


Condenser Dryer: anyone has one?
Created by joker97, last reply by graemew on 18-Jun-2013 21:08 (31 replies)
Pages... 2 3


I am been sued - HELP!
Created by BaaaaD, last reply by CYaBro on 20-Jun-2013 00:24 (59 replies)
Pages... 2 3 4


Slow YouTube Response
Created by SneakerPimps, last reply by mercutio on 18-Jun-2013 21:34 (23 replies)
Pages... 2


Suggestions for good Windows FTP client please?
Created by freitasm, last reply by myfullflavour on 19-Jun-2013 23:27 (22 replies)
Pages... 2


Anyone else watching paint dry?
Created by gnfb, last reply by DravidDavid on 19-Jun-2013 19:53 (40 replies)
Pages... 2 3



Geekzone Jobs »
Most recent NZ jobs in technology:

Website needed
Posted 19-Jun-2013 22:38

Solution Architect - Pre-Sales element!
Posted 19-Jun-2013 22:38

Senior Business Analyst
Posted 19-Jun-2013 19:38

Java Developer
Posted 19-Jun-2013 19:38

RF Tester
Posted 19-Jun-2013 19:38

Motivated Systems Administrator
Posted 19-Jun-2013 19:38

Senior ASP.Net Developer
Posted 19-Jun-2013 19:38


Geekzone Live »
Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.

Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.