Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-27-2017, 07:01 AM
mihnea96 mihnea96 is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Novice
Adding tab in Ribbon
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default Adding tab in Ribbon

Hi ,
I'm trying to add a custom tab in the ribbon using the below code (which i've also used for Excel with little modifications and it worked) and it doesn't work. the problem is that it runs and doesn't give any error but the ribbon is not in the document. I've also tried to put the file in the "\AppData\Local\Microsoft\Office\" folder but doesn't do anything. Could you kindly help me, please?


Thanks!

Code:
Sub test()

Dim wd As word.Application
Dim Doc As word.Document
Dim VBP As Object, VBC As Object, CM As Object, FM As Object
    Dim strProcName As String
   Set wd = CreateObject("Word.Application")
   wd.Visible = True
   Set Doc = wd.Documents.Add

Dim hFile As Long
Dim path As String, fileName As String, ribbonXml As String, User As String

hFile = FreeFile
User = Environ("HomePath")
path = "C:" & User & "\AppData\Local\Microsoft\Office\"
fileName = "Word Customizations.officeUI"
    
ribbonXml = "<mso:customUI      xmlns:mso='http://schemas.microsoft.com/office/2009/07/customui'>" & vbNewLine
ribbonXml = ribbonXml + "  <mso:ribbon>" & vbNewLine
ribbonXml = ribbonXml + "    <mso:qat/>" & vbNewLine
ribbonXml = ribbonXml + "    <mso:tabs>" & vbNewLine
ribbonXml = ribbonXml + "      <mso:tab id='mso_c1.109B239D' label='Formatting' insertBeforeQ='mso:TabDeveloper'>" & vbNewLine
ribbonXml = ribbonXml + "        <mso:group id='mso_c2.109B239D' label='Export' imageMso='ViewFullScreenView' autoScale='true'>" & vbNewLine
ribbonXml = ribbonXml + "          <mso:button id='x1:startExport_0_109F2716' " & vbNewLine
ribbonXml = ribbonXml + "imageMso='ViewFullScreenView'onAction='startExport' visible='true'/>" & vbNewLine
ribbonXml = ribbonXml + "        </mso:group>"
ribbonXml = ribbonXml + "      </mso:tab>" & vbNewLine
ribbonXml = ribbonXml + "    </mso:tabs>" & vbNewLine
ribbonXml = ribbonXml + "  </mso:ribbon>" & vbNewLine
ribbonXml = ribbonXml + "</mso:customUI>"
    
Open path & fileName For Output Access Write As hFile
Print #hFile, ribbonXml
Close hFile
Reply With Quote
  #2  
Old 07-28-2017, 06:00 AM
Guessed's Avatar
Guessed Guessed is offline Adding tab in Ribbon Windows 10 Adding tab in Ribbon Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,973
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

The ribbon code needs to be a valid text file that gets inserted inside a document or template. Typically this is done by using a third party tool which also creates the additional references in associated embedded files.

I don't know how to use vba to inject the ribbon code inside a Word document so I can't help you with that. Some useful references to get you started are:
http://www.softpedia.com/get/Program...n-Editor.shtml
http://gregmaxey.com/word_tip_pages/...bbon_main.html
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 07-28-2017, 06:35 AM
gmaxey gmaxey is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Here at least your customization file name is wrong. You are also missing whitespace before the onAction attribute. Groups don't have images associated with them.

You are aware that your code is going to destroy any existing ribbon or QAT customizations. Correct?

Code:
hFile = FreeFile
  User = Environ("HomePath")
  path = "C:" & User & "\AppData\Local\Microsoft\Office\"
  fileName = "Word.officeUI" '*** This is the filename that works here.
  ribbonXml = "<mso:customUI xmlns:mso='http://schemas.microsoft.com/office/2009/07/customui'>" & vbNewLine
  ribbonXml = ribbonXml + "  <mso:ribbon>" & vbNewLine
  ribbonXml = ribbonXml + "    <mso:qat/>" & vbNewLine
  ribbonXml = ribbonXml + "    <mso:tabs>" & vbNewLine
  ribbonXml = ribbonXml + "      <mso:tab id='mso_c1.109B239D' label='Formatting' insertBeforeQ='mso:TabDeveloper'>" & vbNewLine
  ribbonXml = ribbonXml + "        <mso:group id='mso_c2.109B239D' label='Export' autoScale='true'>" & vbNewLine
  ribbonXml = ribbonXml + "          <mso:button id='x1:startExport_0_109F2716' " & vbNewLine
  ribbonXml = ribbonXml + "imageMso='ViewFullScreenView' onAction='startExport' visible='true'/>" & vbNewLine
  ribbonXml = ribbonXml + "        </mso:group>"
  ribbonXml = ribbonXml + "      </mso:tab>" & vbNewLine
  ribbonXml = ribbonXml + "    </mso:tabs>" & vbNewLine
  ribbonXml = ribbonXml + "  </mso:ribbon>" & vbNewLine
  ribbonXml = ribbonXml + "</mso:customUI>"
  Open path & fileName For Output Access Write As hFile
  Print #hFile, ribbonXml
  Close hFile
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 07-29-2017, 03:01 AM
mihnea96 mihnea96 is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Novice
Adding tab in Ribbon
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

So there is no way i could just add a new tab to the ribbon using VBA? I'm not very familiar to xml, but is it possible to create the tab in xml and attach it somehow to a macro-enabled word doc? I would like to use the macro-enabled doc on other computers as an install file as i have some other macros to installed.
Reply With Quote
  #5  
Old 07-29-2017, 04:56 AM
gmaxey gmaxey is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

That code I posted put in your earlier macro will, but like I said it will destroy any existing customization the user has created. You are overwriting the content of your file with yours.

Did you look at the links that Guessed provided?

You don't install macros. Macros are part of the VBProject of a document or template. A document or template can have RibbonXML that customizes the ribbon or Qat. Documents are opened on other computers while templates can be loaded manually or automatically when Word starts.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 07-29-2017, 10:13 AM
gmaxey gmaxey is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You might find this entertaining:

http://www.vbaexpress.com/forum/show...192#post366192
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 07-31-2017, 02:07 AM
mihnea96 mihnea96 is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Novice
Adding tab in Ribbon
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

update:
i've been looking on your suggestions guys and ended using "Office Ribbon Editor" to create the tab. yet i've encountered another problem: (my project is a Macro-Enabled template) when opening the document, a window pops-up and asks to choose the xml expansion pack. it has 2 options "No XML expansion pack" and "Microsoft Actions Pane 3".
the problem is that it pops up every time i open the document. how can i make this disappear?
Reply With Quote
  #8  
Old 07-31-2017, 04:44 AM
gmaxey gmaxey is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Try this on a copy of your file:

Code:
Sub ScratchMacro()
Dim oXMLSR As XMLSchemaReference
  For Each oXMLSR In ActiveDocument.XMLSchemaReferences
    If InStr(oXMLSR.NamespaceURI, "ActionsPane") > 0 Then
      oXMLSR.Delete
    End If
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 07-31-2017, 05:12 AM
mihnea96 mihnea96 is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Novice
Adding tab in Ribbon
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

Hi,
I've made a copy of my macro-enabled template, when opened it, the "Choose XML Expansion Pack" window popped-up, pasted the code in vb, ran the code, saved the project, closed vb and then closed the document and when opening it again the "Choose XML Expansion Pack" still pops-up. What should i do?
Reply With Quote
  #10  
Old 07-31-2017, 11:24 AM
mihnea96 mihnea96 is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Novice
Adding tab in Ribbon
 
Join Date: Apr 2017
Posts: 26
mihnea96 is on a distinguished road
Default

hey,
i've managed to do the ribbon tab with the buttons and beside the "Choose XML Expansion Pack" window i have another problem: i want to make this tab appear in every document that i open. i've tried replacing the Normal.dotm template but the buttons don't work. i've tried to put the "Sub start(control IRRibbonControl)" code inthe template but can't overwrite it. can you help me sort this out please?

Thanks in advance!
Reply With Quote
  #11  
Old 07-31-2017, 11:29 AM
gmaxey gmaxey is offline Adding tab in Ribbon Windows 7 32bit Adding tab in Ribbon Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Why don't you attached your template file so we can see what you have done.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
import ribbon in word, ribbon in vba, word ribbon



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding tab in Ribbon too many clicks with ribbon - ribbon content disappears Rewster Word 2 05-12-2017 08:19 AM
Adding a New Ribbon Tab using XML Script rdross51 Word VBA 1 06-12-2016 04:52 AM
How to import the customized ribbon to Word without overwriting the existing Ribbon? SharonSh Word VBA 0 09-26-2013 11:47 PM
Excel 2010 Ribbon look like 2007's Ribbon esotop Excel 0 03-22-2011 07:05 PM
Adding tab in Ribbon Lost Ribbon Tab bigred17 Word 6 09-24-2009 09:02 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:58 AM.


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