飛艷小屋

          程序--人生--哲學(xué)___________________歡迎艷兒的加入

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            52 Posts :: 175 Stories :: 107 Comments :: 0 Trackbacks
          8月3日
          這些VBA代碼會有用
          QQ:有沒有辦法得到一個excle表的行的總數(shù)和列的總數(shù)??
          AA:
          xlSheet.UsedRange.Rows.Count
          xlSheet.UsedRange.Cols.Count

          QQ:
          如何打開一個word的模板!
          最近做一個word的模板程序,打開word是Set NewDoc = MyWord.Documents.Add
          這是一個新的doc,名字叫文檔1(后面會累加,自動的),但是現(xiàn)在我希望直接新建打開一個我寫好的模板程序,名字還是叫文檔1。請問應(yīng)該怎么寫!
          AA:
          On Error Resume Next '忽略錯誤
          Set Wrd = GetObject(, "Word.Application") '查找一個正在運(yùn)行的Word拷貝
          If Err.Number <> 0 Then '如果 Word 沒有運(yùn)行則
          Set Wrd = CreateObject("Word.Application") '運(yùn)行它
          End If
          Err.Clear '清除發(fā)生錯誤的 Err 對象
          On Error GoTo 0 '保留普通錯誤進(jìn)程

          Dim dot As String
          Dim doc As String
          Wrd.Visible =true
          dot = "C:\temp.dot"
          doc = "c:\temp.doc"
          Documents.Open FileName:=dot, _
          ConfirmConversions:=False, ReadOnly:=True, AddToRecentFiles:=False, _
          PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
          WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
          0
          Wrd.ActiveDocument.Close
          Wrd.Documents.Add Template:=dot, NewTemplate:=False

          '結(jié)果系列操作
          ActiveDocument.SaveAs FileName:=doc, FileFormat:=wdFormatDocument, _
          LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
          :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
          SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
          False
          '打印出來
          ActiveDocument.PrintOut FileName:=doc, Range:=wdPrintAllDocument, Item:= _
          wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
          ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
          False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
          PrintZoomPaperHeight:=0
          Wrd.ActiveDocument.Close

          WORD中打字
          Selection.TypeText Text:="您好,先生"

          如何讓W(xué)ord的保存命令調(diào)用我自己編寫的保存方法?
          在doc文檔被修改以后,在退出的時候當(dāng)提示用戶文檔已經(jīng)修改,問是否保存
          和直接點(diǎn)擊保存按鈕的時候,能否讓W(xué)ord去調(diào)用我自己編寫的SaveDoc方法,
          如何實(shí)現(xiàn)?
          創(chuàng)建名為“FileSave”的宏,把你的代碼寫入在這個宏中。當(dāng)點(diǎn)擊“保存”按鈕或退出程序要求“保存”時,都會直接執(zhí)行你的“FileSave”宏,而不再執(zhí)行Word的內(nèi)置命令。


          怎么樣判斷Word文檔中有沒有圖片?
          Word里的圖片包括兩種(據(jù)我所知),樓上的漏掉了InlineShapes
          If ActiveDocument.Shapes.Count + ActiveDocument.InlineShapes.Count > 0 Then
          MsgBox "esit"
          Else
          MsgBox "Document doesn't contain a shape"
          End If


          QQ:怎樣在程序中把圖片寫入到word中。
          AA:
          功能是:在指定位置插入圖片并設(shè)置圖片的格式(包括設(shè)置為襯托于文字下    方)
          Sub 設(shè)置圖片格式()
          Selection.InlineShapes.AddPicture FileName:="D:\Mypicture\800x600.jpg", _
          LinkToFile:=False, SaveWithDocument:=True
          Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
          Selection.InlineShapes(1).ConvertToShape.Select
          Selection.ShapeRange.Fill.Visible = msoFalse
          Selection.ShapeRange.Fill.Transparency = 0#
          Selection.ShapeRange.Line.Weight = 0.75
          Selection.ShapeRange.Line.DashStyle = msoLineSolid
          Selection.ShapeRange.Line.Style = msoLineSingle
          Selection.ShapeRange.Line.Transparency = 0#
          Selection.ShapeRange.Line.Visible = msoFalse
          Selection.ShapeRange.LockAspectRatio = msoTrue
          Selection.ShapeRange.Height = 361.4
          Selection.ShapeRange.Width = 481.6
          Selection.ShapeRange.PictureFormat.Brightness = 0.5
          Selection.ShapeRange.PictureFormat.Contrast = 0.5
          Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic
          Selection.ShapeRange.PictureFormat.CropLeft = 0#
          Selection.ShapeRange.PictureFormat.CropRight = 0#
          Selection.ShapeRange.PictureFormat.CropTop = 0#
          Selection.ShapeRange.PictureFormat.CropBottom = 0#
          Selection.ShapeRange.RelativeHorizontalPosition = _
          wdRelativeHorizontalPositionColumn
          Selection.ShapeRange.RelativeVerticalPosition = _
          wdRelativeVerticalPositionPage
          Selection.ShapeRange.Left = wdShapeCenter
          Selection.ShapeRange.Top = wdShapeCenter
          Selection.ShapeRange.LockAnchor = False
          Selection.ShapeRange.WrapFormat.AllowOverlap = True
          Selection.ShapeRange.WrapFormat.Side = wdWrapBoth
          Selection.ShapeRange.WrapFormat.DistanceTop = CentimetersToPoints(0)
          Selection.ShapeRange.WrapFormat.DistanceBottom = CentimetersToPoints(0)
          Selection.ShapeRange.WrapFormat.DistanceLeft = CentimetersToPoints(0.32)
          Selection.ShapeRange.WrapFormat.DistanceRight = CentimetersToPoints(0.32)
          Selection.ShapeRange.WrapFormat.Type = 3
          ‘實(shí)際上真正有用的是下面的語句設(shè)置圖片為襯托于文字下方
          Selection.ShapeRange.ZOrder msoSendBehindText
          End Sub

          QQ:有沒有方法,把一個word文件,按編號返回一段一段的段落文章。
          比如
          1 XXXX
          1.1 YYYY
          1.1.1 ZZZZ
          QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
          1.1.2 SSSS
          PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP

          能夠返回 一個編號對應(yīng)的一個標(biāo)題和一段話。
          謝謝
          AA:
          加載Microsoft Word 9.0 Object Library
          Dim dcApp As Word.Application
          Dim dcWd As Word.Document

          Private Sub Form_Load()
          Set dcApp = New Word.Application
          Set dcWd = dcApp.Documents.Open("c:\rpt.doc")

          For i = 1 To dcWd.Paragraphs.Count
          Debug.Print dcWd.Paragraphs(i).Range.Text
          Next


          dcWd.Close
          Set dcWd = Nothing
          dcApp.Quit
          Set dcApp = Nothing
          End Sub

          QQ:如何用vb實(shí)現(xiàn)在word的bookmark后插入字符
          在word模版中指定了boolmark:a,
          Dim wrdapp As Word.Application
          Dim wrddoc As Word.Document
          Dim strFileName As String
          Dim i As Variant
          dim s as string

          s="要插入的字符"
          Set wrdapp = CreateObject("Word.Application")
          strFileName = App.Path & "\temp.dot"
          Set wrddoc = wrdapp.Documents.Open(strFileName)
          i = wrddoc.Range.GoTo(wdGoToBookmark, , , "a")
          后面該如何寫,才能將s插入到bookmark后面?另外我上面的代碼正確嗎?謝謝
          ??????????????


          QQ: VBA:在word文檔中搜索單詞“審稿人”,將光標(biāo)移到它后面,插入圖片?怎么實(shí)現(xiàn)!!!
          我現(xiàn)在可以打開文件和插入圖片了,就是沒有搜索單詞、移動光標(biāo)、插入指定大小的圖片的功能,那位老大出來指點(diǎn)指點(diǎn)呀?

          我的代碼如下:
          Option Explicit
          Dim Doc As New Document
          Dim Visi As Boolean
          Dim wordApp As Word.Application
          Dim docWord As Word.Document
          Private Sub Command2_Click()
          Set wordApp = New Word.Application
          Set docWord = Word.Documents.Open("D:\test.doc")
          ActiveDocument.Shapes.AddPicture ("d:\shan.jpg")
          docWord.Save
          docWord.Close
          wordApp.Application.Quit()
          End Sub
          AA:
          wordApp.Find.ClearFormatting

          wordApp.Find.Text = "審稿人"
          wordApp.Find.Replacement.Text = ""
          wordApp.Find.Forward = True
          wordApp.Find.Wrap = wdFindContinue
          wordApp.Find.Format = False
          wordApp.Find.MatchCase = False
          wordApp.Find.MatchWholeWord = False
          wordApp.Find.MatchByte = True
          wordApp.Find.CorrectHangulEndings = False
          wordApp.Find.MatchAllWordForms = False
          wordApp.Find.MatchSoundsLike = False
          wordApp.Find.MatchWildcards = False
          wordApp.Find.MatchFuzzy = False

          wordApp.Find.Execute


          QQ:請問如何將加載的菜單不是以懸浮的菜單形式出現(xiàn)?
          AA:CommandBar的Position屬

          QQ: 在vb 中將word文件保存為純文本
          AA:
          Private Sub Command1_Click()
          Dim oW As Object, oD As Object, x As Object
          Set oW = CreateObject("word.application")
          Set oD = oW.documents.open("c:\aaa.doc")
          'oW.Visible = True
          For Each x In oD.words
          Text1 = Text1 & x
          Next x
          Open "c:\bbb.txt" For Output As #1
          Print #1, Text1
          Close #1
          oW.quit
          End Sub


          QQ:怎么在一個word文檔的最后插入東西
          AA:
          WORD XP的VB幫助中有示例:
          本示例在名為“Changes.doc”的文檔末尾插入文本。“For Each...Next”語句用來判斷此文檔是否已打開。

          For Each aDocument In Documents
          If InStr(LCase$(aDocument.Name), "changes.doc") Then
          Set myRange = Documents("Changes.doc").Content
          myRange.InsertAfter "the end."
          End If
          Next aDocument

          QQ:在WORD的宏里如何編寫查詢頁數(shù)和行數(shù),
          AA:
          ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
          ActiveDocument.BuiltInDocumentProperties(wdPropertyLines)


          QQ:請問網(wǎng)頁考到word后,那個向下的箭頭是什么標(biāo)記,如何自動替換掉?手工替換很麻煩阿!但又不知道這是什么標(biāo)記,無法下手阿。急用!!
          AA:
          手工換行符

          可以用查找替換的,或者試試這個

          Sub blankdel()
          Dim i As Integer
          For i = ActiveDocument.Paragraphs.Count To 1 Step -1
          ActiveDocument.Paragraphs(i).Range.Select
          a = Selection.Words.Count
          If a = 1 Then
          Selection.Delete
          m = m + 1
          End If
          Next i
          MsgBox "共刪除空白段落" & m & "個"
          End Sub


          按ALT+F11,把代碼COPY進(jìn)去運(yùn)行一下就行了


          QQ:請問怎么樣用word對象中控制word的分頁?
          AA:
          我剛剛試出來的:此VB6下的代碼可以解你問題

          Set pword = CreateObject("Word.Application")
          pword.Documents.Add dotName, False
          pword.WindowState = 2 'wdWindowStateMinimize '2

          pword.Selection.InsertBreak wdPageBreak


          QQ:我想控制用戶只能修改Word文件的部分內(nèi)容,所以需要設(shè)置部分區(qū)域?yàn)橹蛔x,不知道該用什么方法,請大家賜教。
          AA:
          Selection.InsertBreak Type:=wdSectionBreakContinuous
          ActiveDocument.Sections(1).ProtectedForForms = False
          ActiveDocument.Sections(2).ProtectedForForms = True
          ActiveDocument.Protect Password:="", NoReset:=False, Type:= _
          wdAllowOnlyFormFields


          QQ:請問怎么插入圖片的
          AA:
          Dim myShape As Shape
          Dim MyInshape As InlineShape
          '插入一個嵌入式圖片對象
          Set MyInshape = Selection.InlineShapes.AddPicture(FileName:="D:\pic001.jpg", _
          LinkToFile:=False, SaveWithDocument:=True)
          '將InlineShape對象轉(zhuǎn)變?yōu)镾hape對象
          Set myShape = MyInshape.ConvertToShape
          '使圖片浮于文字上方
          myShape.WrapFormat.Type = wdWrapNone


          QQ:如何訪問表格單元格內(nèi)容
          AA:
          objWordDoc.Tables(3).Cell(1, 1).Range.Text
          posted on 2005-12-06 15:51 天外飛仙 閱讀(4020) 評論(3)  編輯  收藏 所屬分類: .net

          Feedback

          # re: VB代碼word,excel 2006-12-06 18:08 hdp
          用vba如何把word 中的指定字符寫到到execl指定的單元格  回復(fù)  更多評論
            

          # 如何禁止插入到word中的圖片被拖動[未登錄] 2007-12-27 10:04 jack
          如何禁止插入到word中的圖片被拖動  回復(fù)  更多評論
            

          # re: VB代碼word,excel 2009-01-27 11:02 lwpc4203
          VB 寫入word以后如何實(shí)現(xiàn)換行呢?  回復(fù)  更多評論
            

          主站蜘蛛池模板: 景泰县| 福清市| 淄博市| 灌阳县| 鱼台县| 海安县| 新兴县| 屏边| 汶上县| 洱源县| 太谷县| 大宁县| 太仆寺旗| 铅山县| 什邡市| 柏乡县| 余姚市| 大田县| 定陶县| 双牌县| 佛冈县| 福贡县| 博乐市| 梁河县| 苍梧县| 福安市| 东乌珠穆沁旗| 太湖县| 上饶市| 静乐县| 米林县| 哈尔滨市| 凤冈县| 东乌珠穆沁旗| 迁西县| 兴山县| 洛南县| 昔阳县| 壤塘县| 清水县| 棋牌|