Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-21-2015, 12:15 AM
jenniferfoster jenniferfoster is offline VBA scripting / table Windows 8 VBA scripting / table Office 2010 32bit
Novice
VBA scripting / table
 
Join Date: Aug 2015
Posts: 2
jenniferfoster is on a distinguished road
Default VBA scripting / table

Hello, I hope I can get some help here. I need to edit the script below. I have a table which has variables in it. This table is always the last page of every document. My boss now wants this variable table to be situated at the front of documents. The macro (named macro2) does not run and the bookmark moves to other tables throughout the document when I moved the table to the front of documents. Seems like it finds and replaces fields and after each find and replace it goes to the top of the document, not sure - maybe it is set up to go to the last table in the document - I'm not sure and cannot work it out from looking at the script. Can someone who is knowledgeable with script writing please help me...... Our workplace has upgraded their systems from 2003 to 2010 and updating everything including changing them. Thank you in advance and I hope I make sense!

Sub Macro2()
Dim vTest As Long

Dim vFlag, dummy, xx, yy, zz As Integer
ct = 1
vFlag = 0

Application.ScreenUpdating = False
ActiveWindow.View.ShowHiddenText = True
On Error Resume Next ' Defer error handling.
Err.Clear

'On Error GoTo NotAPrecedentLetter
Selection.GoTo What:=wdGoToBookmark, name:="PLF"
If Err.Number <> 0 Then
' Msg = "Error # " & Str(Err.Number) & " was generated by " _
' & Err.Source & Chr(13) & Err.Description
' MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
Else
Call sInsertLetterSetup
End If

'NotAPrecedentLetter:
On Error GoTo NoPrecedentCodes
Selection.GoTo What:=wdGoToBookmark, name:="start"
Selection.Tables(1).Select
tblSize = Selection.Rows.Count

Selection.MoveUp Unit:=wdLine, Count:=1

ReDim List1(tblSize + 1)


yy = ActiveDocument.Tables.Count


'this macro assumes variable code labels have the following
'format only : [number{s}][letter(s)][period]
'for example : 12A. or 12A or 12 or 1
'where [letter(s)] and [period] are optional

For xx = 1 To tblSize Step 1
ActiveDocument.Tables(yy).Cell(xx, 1).Select
List1(xx).sNumber = Selection


'store integer value of variable number
'used in comparison in PrecdentForm code
dummy = Val(List1(xx).sNumber)
List1(xx).iNumber = Str(dummy)


'check to see if a "Return" was included in selection
MyPosCR = InStr(1, List1(xx).sNumber, vbCr, vbTextCompare)
If MyPosCR > 0 Then
List1(xx).sNumber = Mid(List1(xx).sNumber, 1, MyPosCR - 1)
End If

'check to see if a "period" was included in selection
MyPosPeriod = InStr(1, List1(xx).sNumber, ".", vbTextCompare)
If MyPosPeriod > 0 Then
List1(xx).sNumber = Mid(List1(xx).sNumber, 1, MyPosPeriod - 1)
End If



ActiveDocument.Tables(yy).Cell(xx, 2).Select
List1(xx).sLabel = Selection

'check to see if a "Return" was included in selection
MyPosCR = InStr(1, List1(xx).sLabel, vbCr, vbTextCompare)
If MyPosCR > 0 Then
List1(xx).sLabel = Mid(List1(xx).sLabel, 1, MyPosCR - 1)
End If

Next xx

Load PrecedentForm
PrecedentForm.Show

Unload PrecedentForm

If ct <= tblSize Then
ActiveDocument.Tables(yy).Cell(ct, 1).Select
Selection.HomeKey Unit:=wdLine
ActiveDocument.Bookmarks("start").Delete
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, name:="start"
.DefaultSorting = wdSortByName
.ShowHidden = False


End With
Selection.SplitTable

MsgBox "Make edits; then click GO button to continue updating"
vFlag = 1
Else
Selection.HomeKey Unit:=wdStory
'Selection.GoTo What:=wdGoToBookmark, Name:="text"
MsgBox "Precedent Variable Update Complete"
vFlag = 0
End If

Selection.HomeKey Unit:=wdStory
Selection.Find.Replacement.ClearFormatting
' With Selection.Find
' .Text = "vbCR"
' .Replacement.Text = "^p"
' .Forward = True
' .Wrap = wdFindContinue
' End With
With Selection.Find
.Text = Chr(13) + Chr(10)
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
If vFlag = 1 Then
Selection.HomeKey Unit:=wdStory
Selection.Find.Execute FindText:="*" + Trim(List1(ct).sNumber) + "*"
End If

NoPrecedentCodes:
End Sub
Reply With Quote
 

Tags
vba tables macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA scripting / table Move table cell contents from one table to another table or cell in same table donaldadams1951 Word VBA 4 02-04-2015 03:54 PM
Pivot Table Question- Can the table display in the order the boxes were checked/selected? blackjack Excel 0 09-13-2014 08:57 PM
VBA scripting / table help with scripting mrokoua Outlook 1 08-26-2014 03:52 AM
How to change the path of a table copied by excel in word as linked table RTF? Cristin7 Word VBA 3 03-10-2014 05:25 AM
Scripting error presented when emails are opened from one specific sender Mr Davo Outlook 0 05-30-2012 07:01 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:22 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