VBA Word - Exemplos de Códigos - T a Z - Em ordem alfabética.


Termo de Responsabilidade





 « T »







Table of Contents, Update Page Numbers Only:





ActiveDocument.TablesOfContents(1).UpdatePageNumbers






Table, Go to 1st Table in Document:






Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, _    Count:=1, Name:=""






Table, Show Table Gridlines:






ActiveWindow.View.TableGridlines = True






Table, Take Borders Off Table:






With Selection.Cells    .Borders(wdBorderLeft).LineStyle = wdLineStyleNone    With .Borders(wdBorderRight)       .LineStyle = wdLineStyleSingle       .LineWidth = wdLineWidth075pt       .ColorIndex = wdAuto    End With    With .Borders(wdBorderTop)       .LineStyle = wdLineStyleSingle       .LineWidth = wdLineWidth075pt       .ColorIndex = wdAuto    End With    With .Borders(wdBorderBottom)       .LineStyle = wdLineStyleSingle       .LineWidth = wdLineWidth075pt       .ColorIndex = wdAuto    End With    .Borders.Shadow = False End With With Options    .DefaultBorderLineStyle = wdLineStyleSingle    .DefaultBorderLineWidth = wdLineWidth050pt    .DefaultBorderColorIndex = wdAuto End With






Table, Total the Numbers






Selection.InsertFormula Formula:="=SUM(ABOVE)", _    NumberFormat:="#,##0.00"






Tabs, Clear All:






Selection.ParagraphFormat.TabStops.ClearAll ActiveDocument.DefaultTabStop = InchesToPoints(0.5)






Tabs, Tab Stop, Add:






Selection.ParagraphFormat.TabStops.Add _    Position:=InchesToPoints(6.63), _    Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces






TextBox, Is There Something in a Text Box:






If txtStuff.Text := "" Then    MsgBox("There is nothing in the text box") End If






Text File, Open, Write to & Close:






Open "C:\Temp\MyFile.txt" For Output As #1 Write #1, "This is some text." Close #1






Text File, Open, Read Data Into Variables & Close: 







This example assumes that "C:\Temp\MyFile.txt" is a text file with a few lines of text in it, each line containing a string in quotations and a number separated by a comma. For example:







     "Howdy Doodie", 12345      "Good Morning", 67890







Dim MyString, MyNumber Open "C:\Temp\MyFile.txt" For Input As #1 Do While Not EOF(1)                'Loop until end of file Input #1, MyString, MyNumber       'Read data into two variables MsgBox (MyString & " " & MyNumber) 'Show variable contents in message box Loop Close #1





« U »








Underline, Turn On Single Underline:






Selection.Font.Underline = wdUnderlineSingle






Underline, Turn Off Single Underline:






Selection.Font.Underline = wdUnderlineNone






Unload Forms - Unload All of Them (i.e., at End of Program):






Dim frm as Userform For Each frm in Userforms    Unload frm Next frm






User Info, Set User Initials in Tools, User Info:






Application.UserInitials = "[initials]"   OR (If getting user initials from an .ini file:) Application.UserInitials = System.PrivateProfileString(strIniFile, _      "Initials", strUserName)      OR Application.UserInitials = strUserInitials






User Info, Set User Name in Tools, User Info:






Application.UserName = "[UserName]"      OR Application.UserName = cbxUserName.Value   OR Application.UserName = strUserName





« V »








Value, Get Value of a Number From a String:






intNumber = Val(txtNumber.Text)






Variable, Declare:






Note: "Dim" stands for "Dimension" Dim [VariableName] as [TypeOfVariable] Example: Dim strName as String There are many kinds of Variables and ways to declare them. Look under VBA "Help" for a listing and explanation.






View, Bookmarks:






ActiveWindow.View.ShowBookmarks = True






View, Current Page Header:






ActiveWindow.ActivePane.View.SeekView = _    wdSeekCurrentPageHeader






View, Field Codes (with all the junk):






ActiveWindow.View.ShowFieldCodes = _    Not ActiveWindow.View.ShowFieldCodes With ActiveWindow    With .View       .ShowFieldCodes = True    End With End With






View, Field Codes:






ActiveWindow.View.ShowFieldCodes = True






View, Footer:






ActiveWindow.ActivePane.View.SeekView = _    wdSeekCurrentPageFooter






View, Header:






ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader






View, Header (with all the junk):






If ActiveWindow.View.SplitSpecial := wdPaneNone Then    ActiveWindow.Panes(2).Close End If If ActiveWindow.ActivePane.View.Type = wdNormalView Or _    ActiveWindow.ActivePane.View.Type = wdOutlineView Or _    ActiveWindow.ActivePane.View.Type = wdMasterView Then _    ActiveWindow.ActivePane.View.Type = wdPageView End If ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader






View, Main View (Close Header or Footer:)






ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument






View, Options:






Application.DisplayStatusBar = True With ActiveWindow    .DisplayHorizontalScrollBar = True    .DisplayVerticalScrollBar = True    .DisplayVerticalRuler = True    .DisplayScreenTips = True    With .View       .ShowAnimation = True       .ShowPicturePlaceHolders = False       .ShowFieldCodes = False       .ShowBookmarks = False       .FieldShading = wdFieldShadingWhenSelected       .ShowTabs = False       .ShowSpaces = False       .ShowParagraphs = False       .ShowHyphens = False       .ShowHiddenText = False       .ShowAll = True       .ShowDrawings = True       .ShowObjectAnchors = False       .ShowTextBoundaries = False       .ShowHighlight = True    End With End With






View, Turn Off View Bookmarks:






ActiveWindow.View.ShowBookmarks = False





« W »








Window, Maximize Application Window:






Application.WindowState = wdWindowStateMaximize





« X »
« Y »« Z »







Reference::
Tags: Application, Automation, Macro, Microsoft, MS, Office, VBA, Word, code

Inline image 1

Nenhum comentário:

Postar um comentário

diHITT - Notícias