Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-29-2014, 07:59 AM
gmaxey gmaxey is offline Macro to extract AutoTextList Field Screen Tip text Windows 7 32bit Macro to extract AutoTextList Field Screen Tip text Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Marrick,



I have streamlined your code a bit. Is the page number issue due to have the field code displayed? At least with the sample document you posted the page numbers appear correct here.

Code:
Sub Extract_AutoTextList_ScreenTip()
  Dim strFieldData() As String
  Dim oDoc As Word.Document
  Dim strFileName As String
  Dim oDocReport As Word.Document
  Dim oTbl As Word.Table
  Dim oRow As Word.Row
  Dim lngIndex As Long
  strFieldData() = fcnFieldData
  'If CountATLFields = 0 Then
    'MsgBox ("There are no AutoTextLink fields in this document."), , "Field Count"
    'Exit Sub
  'End If
  Set oDoc = ActiveDocument
  strFileName = oDoc.FullName
  'Create a new document for the extract
  Set oDocReport = Documents.Add
  'Insert a 3-column table for the extract
  Application.ScreenUpdating = False
  With oDocReport
    .Content = ""
    'Set orientation to landscape
    .PageSetup.Orientation = wdOrientLandscape
    Set oTbl = .Tables.Add(Range:=Selection.Range, _
       NumRows:=UBound(strFieldData, 2) + 3, NumColumns:=3)
    End With
    With oTbl
      For Each oRow In oTbl.Range.Rows
        oRow.Cells(1).Width = InchesToPoints(0.7)
        oRow.Cells(2).Width = InchesToPoints(2)
        oRow.Cells(3).Width = InchesToPoints(3)
      Next
      With .Rows(1)
        .Cells.Merge
        .Cells(1).Range.Text = "File name: " & strFileName & vbCr & _
        "Created by: " & Application.UserName & vbCr & _
        "Creation date: " & Format(Date, "MMMM d, yyyy")
        .Range.Font.Bold = True
        .Shading.BackgroundPatternColor = wdColorGray125
      End With
      With .Rows(2)
        .Range.Font.Bold = True
        .Cells(1).Range.Text = "Page #"
        .Cells(2).Range.Text = "Display Text"
        .Cells(3).Range.Text = "Screen Tip"
      End With
      For lngIndex = 1 To 6
        With .Borders(lngIndex)
          .LineStyle = wdLineStyleSingle
          .LineWidth = wdLineWidth050pt
          .Color = wdColorAutomatic
        End With
      Next
      With Options
        .DefaultBorderLineStyle = wdLineStyleSingle
        .DefaultBorderLineWidth = wdLineWidth050pt
        .DefaultBorderColor = wdColorAutomatic
      End With
   End With
   For lngIndex = 0 To UBound(strFieldData, 2)
     With oTbl.Rows(lngIndex + 3)
       .Cells(1).Range.Text = strFieldData(0, lngIndex)
       .Cells(2).Range.Text = strFieldData(1, lngIndex)
       .Cells(3).Range.Text = strFieldData(2, lngIndex)
     End With
   Next lngIndex
   Application.ScreenUpdating = True
End Sub

Function fcnFieldData() As String()
Dim lngJunk As Long
Dim oFld As Word.Field
Dim rngStory As Word.Range
Dim arrTemp() As String
Dim arrParts() As String
Dim lngCOunt As Long
  lngCOunt = 0
  'Word missing first Header/Footer bug workaround
  lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
  'Iterate through all story types in the current document
  For Each rngStory In ActiveDocument.StoryRanges
    'Iterate through all linked stories
    Do
      For Each oFld In rngStory.Fields
        If oFld.Type = wdFieldAutoTextList Then
          ReDim Preserve arrTemp(2, lngCOunt)
          arrTemp(0, lngCOunt) = oFld.Code.Information(wdActiveEndPageNumber)
          arrTemp(1, lngCOunt) = oFld.Result
          arrParts = Split(oFld.Code, """")
          arrTemp(2, lngCOunt) = arrParts(1)
          lngCOunt = lngCOunt + 1
        End If
      Next
    'Get next linked story (if any)
    Set rngStory = rngStory.NextStoryRange
    Loop Until rngStory Is Nothing
  Next
  fcnFieldData = arrTemp
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #2  
Old 11-29-2014, 08:37 AM
Marrick13 Marrick13 is offline Macro to extract AutoTextList Field Screen Tip text Windows XP Macro to extract AutoTextList Field Screen Tip text Office 2010 32bit
Competent Performer
Macro to extract AutoTextList Field Screen Tip text
 
Join Date: Jun 2006
Posts: 102
Marrick13 will become famous soon enough
Default Macro to extract AutoTextList Field Screen Tip text

Greg,

I appreciate your attempt to improve the page number capture. Your revision did work with the sample file I sent you. However, when I added screen tip fields to the same sample and ran your revised code, the page numbers were again off by a page. I've attached the sample with new fields and your macro so you can see for yourself.

I think the Microsoft model just doesn't allow for the capture of accurate page numbers in this context.
Attached Files
File Type: docm Screen Tip Format Test-2.docm (48.4 KB, 13 views)
Reply With Quote
Reply

Tags
autotextlist, extract, field



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to extract AutoTextList Field Screen Tip text Macro to find text and replace with form field containing that text iiiiifffff Word VBA 16 06-04-2016 01:47 AM
Macro to find coloured text and replace with form-field/formtext containing that text tarktran Word VBA 1 11-26-2014 08:12 AM
Macro to extract AutoTextList Field Screen Tip text Word 2007 Macro Fillin Field to Text mhblake Word VBA 5 01-08-2014 08:22 AM
Autotextlist Gone Wilson Word 1 04-04-2010 02:44 PM
Macro to extract AutoTextList Field Screen Tip text Extract email address from field zssteen Excel 1 06-19-2009 02:32 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:54 PM.


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