#16
|
||||
|
||||
Instead of asking me what values properties like .LineSpacing and .LineSpacingRule return, how about selecting them in the code and pressing F1. What you are trying to do requires a competent understanding of VBA; I don't propose to hand-feed you with the basics any competent programmer could implement or work out for themselves at every step of the journey. As I said in post #2, the code in the link was: Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#17
|
||||
|
||||
Word uses 'points' as its default measurement units. There are 72 Points in an Inch.
The LineSpacingRule is the setting in the dropdown that you see in the Paragraph dialog. The computer stores the chosen option as numbers rather than text and so that it what it is returning when your macro queries this setting. You can experiment with the paragraph formatting and examine the macro results to work out what the '5' is indicating. It will be one of the following options:
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#18
|
|||
|
|||
Paul
Quote:
Quote:
Andrew Quote:
SamD |
#19
|
|||
|
|||
As I moved on
How can i get bookmark.name as returned value against that particular para. if Bookmark existed with the bookmark.name in a particular paragraph I get error 5941" "the requested member of the collection does not exist. I've made a blunder. Shall appreciate your guidance in correcting and helping me to remove the error Code:
Public Sub ListBasicReturnedObjects() Dim wdActDoc As Document Dim oBkMrk As Bookmark Dim StrData As String, StrSty As String, Sty As Style Dim StrStory As String Dim i As Long Dim strHeader As String Set wdActDoc = ActiveDocument strHeader = "Para No" & Space(5) & "Style" & Space(12) & "Alignment" & Space(2) & "Font Name" & Space(24) & "BookMark" StrData = strHeader & vbCrLf With wdActDoc For i = 1 To .Range.Paragraphs.Count With .Paragraphs(i) StrSty = .Style StrData = StrData & vbCr & Format(i, "#00#") & Space(8) & Mid(StrSty, 1, Len(StrSty)) Set Sty = wdActDoc.Styles(StrSty) If Len(.Style) <= 11 Then StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name '& & vbTab Else StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name End If If wdActDoc.Bookmarks.Exists("mybookmark") = False Then StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name & ActiveDocument.Bookmarks(i).Name 'oBkMrk.Name End If End With Next TextBox1.Text = TextBox1.Text & StrData End With End Sub |
#20
|
||||
|
||||
What are you asking for?
Your code is saying if "mybookmark" doesn't exist then tell me the name of the nth (where n = the paragraph number) bookmark. This will fail as soon as the number of bookmarks is surpassed by the number of paragraphs. Bookmarks can be an insertion point or a range of text either within a single paragraph or across a bunch of content. So if a bookmark exists it could show a range of zero length or span multiple paragraphs.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#21
|
||||
|
||||
Look at the 'logic' of what you're doing:
Code:
For i = 1 To .Range.Paragraphs.Count With .Paragraphs(i) ... If wdActDoc.Bookmarks.Exists("mybookmark") = False Then StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name & ActiveDocument.Bookmarks(i).Name 'oBkMrk.Name End If End With Next Note that you're not asking Word to tell you about a bookmark in 'wdActDoc' (which may no longer be the active document) and you're not even trying to establish that a bookmark with the same index (i) as the paragraph exists before trying to get its name. Hardly surprising you're having problems.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#22
|
|||
|
|||
OMG ! I've misunderstood the bookmark
What i wanted was if paragraph had a book mark Wanted its name and against the para number if you see the loop Each Para is returning the value is like .Alignment , .Range.Font.Name with this wanted addtioinally the bookMark.name if existed against the Paragrpah number Code:
Public Sub ListBasicReturnedObjects3() Dim wdActDoc As Document Dim oBkMrk As Bookmark Dim StrData As String, StrSty As String, Sty As Style, strstylen As Integer Dim StrStory As String Dim gapBetween As Integer Dim i As Long, j As Long, k As Long, bTabOK As Boolean, Rng As Range Dim bldFont As Boolean, undline As Boolean, stkThru As Boolean, strHeader As String, Pos As Integer, newPos As Integer Dim StrRecord As String Set wdActDoc = ActiveDocument '15 strHeader = "Para No" & Space(5) & "Style" & Space(12) & "Alignment" & Space(2) & "Font Name" & Space(24) & "BookMark" StrData = strHeader & vbCrLf With wdActDoc For i = 1 To .Range.Paragraphs.Count With .Paragraphs(i) StrSty = .Style StrData = StrData & vbCr & Format(i, "#00#") & Space(8) & Mid(StrSty, 1, Len(StrSty)) Set Sty = wdActDoc.Styles(StrSty) If Len(.Style) <= 11 Then StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name Else StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name End If What should be the code here in this loop if there is a book mark in the Para of Active document BkMark-Para2 is the bookmark.name. As Para 2 was selected and Book mark name was given as BkMark-Para2 Please see the quoted representation End With Next TextBox1.Text = TextBox1.Text & StrData End With End Sub Quote:
|
#23
|
||||
|
||||
This is how I would do it. Add these lines where you indicated
Code:
For Each aBkmk In .Range.Bookmarks StrData = StrData & vbTab & aBkmk.Name Next aBkmk Dim aBkmk As Bookmark
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#24
|
|||
|
|||
Thanks Andrew
I did the correction. and now clear on Bookmark As further i move on with few trials and tests. What i observed was that another document with total nos paras. were 244 but some ridiculous returned value of font size Format(.Range.Font.Size, "##") Font size should display its size in 2 digits but here few paras. showed the .range.font.size as 9999999 Font name is Times New Roman and size were displayed as 18,12,11... and 9999999 How can the size be retained to 2 digit Code:
If stkThru = True Then StrData = StrData & stkThru & Space(18) & Format(.Range.Font.Size, "##") & Space(18) Else StrData = StrData & stkThru & Space(18) & Format(.Range.Font.Size, "##") & Space(18) End If |
#25
|
||||
|
||||
When a paragraph has more than one font size in it, the 'range' size font will return an undefined value which shows up as a blank font size in the GUI - but in VBA this will show as a number like 999999. There could be a large number of font sizes and typefaces in a single paragraph. You can augment the code to query every location inside a paragraph if an undefined value is encountered for the overall size or typeface but the value of that is dubious.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#26
|
|||
|
|||
Thanks Andrew for the clarification.
Quote:
Any thread reference you could recommend where i can implement the same in my coding. SamD |
#27
|
|||
|
|||
Will it be possible to control the length of wdUndefined number 9999999
when 9999999 is displayed it occupies un-wanted space and the structure is disturbed. In Any manner Can we shorten the 9999999 to 99. if yes then how ? and even if not and still displayed as 9999999 then how can i get equal spacing after 9999999 because other fonts are displayed with 2 digit size. SamD |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Multiple found values from five sheets, multiple returned values in sheet six? | irisha | Excel Programming | 26 | 09-30-2016 01:20 AM |
Macros to move objects prevents moving same objects with arrow keys | BruceM | Word VBA | 1 | 03-10-2015 08:20 AM |
List of Objects for CreateObject | excelledsoftware | Excel Programming | 4 | 09-14-2014 08:47 PM |
Query list of objects and properties in VBA | bshawnr | Word VBA | 1 | 08-22-2013 11:03 PM |
Pivot Table:delete zero values when using calculated objects | Serge 007 | Excel | 1 | 06-05-2013 11:47 AM |