VBA怎麽读取word的页码
亲,代码如下:Private Sub TJYS_Click()Dim d, p As IntegerDim f, ff As ObjectSet fso = CreateObject("Scripting.FileSystemObject")Set ff = fso.getfolder(ThisDocument.Path)d = 0: p = 0For Each f In ff.FilesIf f.Name <> ThisDocument.Name And Left(f.Name, 2) <> "~$" And f.Name Like "*.doc*" Thend = d + 1Documents.Open FileName:=ThisDocument.Path & "\" & f.Namep = p + ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)ActiveDocument.Close FalseEnd IfNext fMsgBox "总共统计了 " & d &; " 个文件,总页数为 " & p &; "页。
", vbOKOnly, "结果"End Sub
怎样在Word中插入页码和页数如图,我想让文档自动生成页码和总页
第一个问题:可以。
光标放在文档里想插入页码的地方,打开--插入-域-,选择“page”(当前页码),如选“numpages”,就是总页码。
文档有修改时,选“全选”-右键-更新域,全部更新即可。
第二个问题:可以。
选中表格中左边一列(插入序号的一列),点一下上面的“项目符号”中的“编号”,就是自动加编号了,中间想加想删都会自动编号。
有人会弄word的目录和插入页码吗?求帮忙,急!!!
Sub Macro2()Dim r, p, r0, p0, rr, ppp= Selection.Information(wdActiveEndPageNumber) '当前页码r= Selection.Information(wdFirstCharacterLineNumber) '当前行'数行数p0 = prr = rDoSelection.MoveDown Unit:=wdLine, Count:=1pp = Selection.Information(wdActiveEndPageNumber)r0 = Selection.Information(wdFirstCharacterLineNumber)If pp > p Then'退回原处Selection.MoveUp Unit:=wdLine, Count:=(rr - r + 1)Exit DoEnd IfIf rr = r0 Then'退回原处Selection.MoveUp Unit:=wdLine, Count:=(rr - r)Exit DoEnd Ifrr = r0LoopMsgBox "当前页码:" & p & vbCrLf &; "本页总行数:" & rrEnd Sub 申请加悬赏分!!!
分了好多节的word通过VBA调出某一节的页码范围
sub test ()istart = InputBox("输入你要打印的起始节")iEnd = InputBox("输入你要打印的结束节") '为了方便搞了两个inputbox,你可以用一个,方法如下:'规定一个格式,然后用instr,left,right等得到起始和结束的节数Dim doc As DocumentDim rngDoc As RangeSet doc = ActiveDocumentSet rngDoc = doc.Range(Start:=doc.Paragraphs(istart).Range.Start, _End:=doc.Paragraphs(iEnd).Range.End)rngDoc.Selectdoc.PrintOut Range:=wdPrintSelectionSet rngDoc = NothingSet doc = Nothingend sub
如何用vba代码将word文档中插入的表格对象内容复制到Excel中
试试下面的代码,在网上找的Sub 宏1()Dim wordapp As ObjectDim mydocDim mypath$, myname$Dim wdRng As ObjectDim pos1%, pos2% '定义找到的字段的首位位置Application.DisplayAlerts = FalseSet wordapp = CreateObject("word.application")mypath = ThisWorkbook.Path & ""myname = Dir(mypath & "*.doc*")Set mydoc = wordapp.Documents.Open(mypath & myname)Set wdRng = mydoc.RangewdRng.Find.Execute ("(一)")pos1 = wdRng.StartSet wdRng = mydoc.RangewdRng.Find.Execute ("五、")pos2 = wdRng.Startmydoc.Range(pos1, pos2).Copy '选中找到的两个字段中间的内容mydoc.Close Falsewordapp.QuitWorksheets("Sheet2").SelectRange("A1").SelectActiveSheet.PasteApplication.ScreenUpdating = TrueApplication.DisplayAlerts = TrueEnd Sub
如何在页码格式中多加入几种格式日常在文档中插入页码的时候,我们...
网上有现成的代码:========要判断 以上表格中如果有空时,则弹出对话框页面=========='当打开Word时弹出对话框 要用户输入内容 Private Sub Document_Open() Dim flag As Boolean flag = True With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Range For i = 2 To 9 Step 1 If Len(.Cells(i).Range.Text) = 2 Then flag = False End If Next If flag = False Then AddHeader.Show End If End With End Sub=====点确定后将页面对话框中的值 插入到word 的页眉表格中==== Private Sub CommandButton1_Click() With ActiveDocument.Sections(1)'Cell(4, 2).Range.InsertBefore (TextBox4.value) ' .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 2).Range.InsertAfter ("aaa") .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 3).Range.Delete .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 3).Range.InsertAfter (TxtFileName.Value) .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 2).Range.Delete .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 2).Range.InsertAfter (TxtSecrecy.Value) .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 4).Range.Delete .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 4).Range.InsertAfter (TxtRev.Value) .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 6).Range.Delete .Headers(wdHeaderFooterPrimary).Range.Tables(1).Cell(2, 6).Range.InsertAfter (TxtID.Value) '页尾的做法' .Footers(wdHeaderFooterPrimary).Range.Text = "Copyright BYD Company Limited" End With AddHeader.Hide End Sub========提问 ================= 比如说sheet1 中A1:A10不为空,用代码判断不为空后,光标移向A11,并且A11=11,B11=22 再录入数据后光标又光标移向A12,并且A12=22,B12=23,依此类推========解决方法:=============================== Sub Text() If IsEmpty([A1]) Then [A1] = "你的数据" Else [A65536].End(xlUp).Offset(1, 0).Value = "你的数据" End If End Sub ========提问 ================= 判断word中表格是否为空========解决方法:==============================='a.Cells.Count=41,46,41+5*7 Dim list%'你的要求可能是这样 With ActiveDocument.Tables(1).Range For i = 41 To 41 + 5 * 7 Step 5 '测得第一项的后面对应的是第41个单元格,相差是5。
所以,step=5 list = list + 1 '利用list来得到是第几项没有加项 If Len(.Cells(i).Range.Text) = 2 Then '因为类回车加+竖线加在一起是2个长度。
所以。
。
这样判断 'n = .Cells(i - 4).Range.Text '取得单元格的内容+回车+竖线 'n = Mid(n, 1, Len(n) - 2) '去掉回车+竖线的,即我们所看到的内容 MsgBox "提示:没有给第" & list & "项打分!", vbOKOnly, "www.excelhome.net" .Cells(i).Range.Select '选中所在的单元格 Exit Sub End If Next End With
如何用vba代码将word文档中插入的表格对象内容复制到Excel中
展开全部 试试下面的代码,在网上找的 Sub 宏1() Dim wordapp As Object Dim mydoc Dim mypath$, myname$ Dim wdRng As Object Dim pos1%, pos2% '定义找到的字段的首位位置 Application.DisplayAlerts = False Set wordapp = CreateObject("word.application") mypath = ThisWorkbook.Path & "" myname = Dir(mypath & "*.doc*") Set mydoc = wordapp.Documents.Open(mypath & myname) Set wdRng = mydoc.Range wdRng.Find.Execute ("(一)") pos1 = wdRng.Start Set wdRng = mydoc.Range wdRng.Find.Execute ("五、") pos2 = wdRng.Start mydoc.Range(pos1, pos2).Copy '选中找到的两个字段中间的内容 mydoc.Close False wordapp.Quit Worksheets("Sheet2").Select Range("A1").Select ActiveSheet.Paste Application.ScreenUpdating = True Application.DisplayAlerts = TrueEnd Sub...
转载请注明出处51数据库 » vba word 插入页码
她的梦是蓝天