VBA Learning Notes (5)-a few useful examples

Source: Internet
Author: User
Tags rowcount

Displays the current page size:

Application.ActiveDocument.Name
Application.ActiveDocument.PaperSize
application.activedocument. Paperheight ("inches")

Application.ActiveDocument.PaperWidth ("inches")
Subuseapplication ()'holds the description.    DimDescription as String        'Get the document description.     withapplication.activedocument Description= _            "Name:"+ . Name + vbCrLf + _            "Description:"+ . Description + vbCrLf + _            "Paper Height:"+ _            CStr(. Paperheight ("inches") + VbCrLf + _            "Paper Width:"+ _            CStr(. PaperWidth ("inches") + VbCrLf + _            "Paper Size:"                'The paper size requires special handling.        Select  Case . PaperSize Casevispapersizes.vispapersizea3 Description= Description +"A3"             Casevispapersizes.vispapersizea4 Description= Description +"A4"             CaseVispapersizes.vispapersizea5 Description= Description +"A5"             Casevispapersizes.vispapersizeb4 Description= Description +"B4"             Casevispapersizes.vispapersizeb5 Description= Description +"B5"             CaseVispapersizes.vispapersizec Description= Description +"C"             Casevispapersizes.vispapersized Description= Description +"D"             CaseVispapersizes.vispapersizee Description= Description +"E"             CaseVispapersizes.vispapersizefolio Description= Description +"Folio"             CaseVispapersizes.vispapersizelegal Description= Description +"Legal"             CaseVispapersizes.vispapersizeletter Description= Description +" Letter"             Casevispapersizes.vispapersizenote Description= Description +"Note"             CaseVispapersizes.vispapersizeunknown Description= Description +"Unknown"        End Select    End  with        'Get the active page description.     withapplication.activepage Description= Description + vbCrLf + _            "Page Width:"+ _            CStr(. Shapes ("thepage"). Cells ("PageWidth")) +_ vbCrLf+"Page Height:"+ _            CStr(. Shapes ("thepage"). Cells ("PageHeight"))            End  with        'Display The Description on screen.    MsgBoxDescription, _ vbinformationOrvbOKOnly, _"Document and Page Description"End Sub

Displays all pages currently.

ActiveDocument.Pages
Option ExplicitSublistpages ()'holds the list of pages.    DimThepages asPages'holds the page information.    DimPagenames as String    DimThispage asPage'Get the list of pages.    SetThepages =ActiveDocument.Pages'Obtain the page information.     for  eachThispageinchthepages'Check for a drawing page.Pagenames = pagenames + Thispage.name +vbCrLfNext        'Display the results.    MsgBoxPagenames, vbinformationOrvbOKOnly,"Drawing Pages in Document"End Sub

Displays all shapes of the current page.

Activepage.shapes
Sublistshapes ()'holds the list of shapes for a page.    DimTheshapes asShapes'Obtain the list of shapes.    SetTheshapes =Activepage.shapes'holds individual shape data.    DimThisShape asShapeDimShapenames as String        'obtain each shape and add it to the list.     for  eachThisShapeinchtheshapes shapenames= Shapenames + Thisshape.name +vbCrLfNext        'Display The results on screen.    MsgBoxShapenames, _ vbinformationOrvbOKOnly, _"Shapes on the current Page"End Sub

Displays cells corresponding to the ShapeSheet.

Activepage.shapes ("xxx"). RowCount
Activepage.shapes ("xxx"). CellsSRC
Sublistcells ()'holds the current shape.    DimTheshape asShape'Loop counter variables.    DimRowCount as Integer    DimCellcount as Integer        'holds the current cell information.    DimThecell asCellDimCellname as String        'obtain a selected shape.
' Shapename,refer before papers SetTheshape = Activepage.shapes ("XXX") 'Open The file that would contain the cell names.Open Thisdocument.path +"\cellnames.txt" forOutput as#1 'Process each of the cells rows. forRowCount =0 toTheshape.rowcount (visSectionProp)-1 'Process Each cell in the row. forCellcount =0 toTheshape.rowscellcount (visSectionProp, RowCount)-1 'obtain the specific cell. SetThecell =theshape.cellssrc (visSectionProp, RowCount, Cellcount)'Save The name of the Cell.Cellname = Thecell.name +vbCrLf'Output the data. Write#1, CellnameNext Next 'Close the file.Close #1 End Sub

Two Helpful Links:

ref:https://msdn.microsoft.com/en-us/library/aa201749

https://msdn.microsoft.com/en-us/library/aa730963 (v=office.12). aspx

VBA Learning Notes (5)-a few useful examples

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.