#1
|
|||
|
|||
VBA insert quick part formula and format as percentage
It seems I've looked everywhere, but can't seem to find the right way to format a quick part formula as percentage. Here is what I've tried.
Code:
Sub test() With ActiveDocument.Tables(1) .Cell(5, 5).Formula Formula:="=A2/B2*100" .Cell(5, 5).Range.Text = Format(.Cell(5, 5), "0.00%") End With End Sub Code:
Sub Macro3() Selection.InsertFormula Formula:="=A2/B2*100", NumberFormat:="0.00%" End Sub |
#2
|
||||
|
||||
There are various ways of doing this. For example:
Code:
ActiveDocument.Tables(1).Cell(5, 5).Formula Formula:="=A2/B2*100 \# ""0.00""" Code:
With ActiveDocument .Fields.Add Range:=.Tables(1).Cell(5, 5).Range, Type:=wdFieldEmpty, Text:="=A2/B2*100 \# 0.00%", PreserveFormatting:=False End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks Paul. So in the end, it was the double quotes I was missing.
|
#4
|
||||
|
||||
I'll have to take your word for that, since you didn't post the code that wasn't working...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Insert landscape page as quick part | melsmiff12 | Word | 1 | 04-28-2017 12:51 PM |
Quick Part Galleries | dfmdfm | Word | 1 | 03-27-2017 04:45 PM |
Quick part building blocks - Formula | lukegwilson96 | Word | 6 | 12-13-2016 10:46 AM |
Insert quick part when cell contains a value | winstond | Word VBA | 1 | 09-30-2014 11:45 AM |
How to Rename a Quick Part | sleake | Word | 14 | 10-14-2013 09:21 AM |