word里的2个简单问题,请大家帮个忙

jam021 2004-07-19 09:45:29
word里的2个简单问题,请大家帮个忙:
1.用VBA实现,new了一个空的word文档,怎样给它加page页,一般打开word后就一页,我现在想给它再加几页,怎么办?
2.用VBA实现,能不能用坐标定义位置然后在相应的位置上写入一些文本,一般一打开word后写字的话是从开始写的,现在我想在一个指定的地方写上一些字,怎么办?
...全文
130 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vansoft 2004-07-20
  • 打赏
  • 举报
回复
上面的保存为frmMain.frm。
下面的保存为word.vbp

Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#D:\WINNT\system32\stdole2.tlb#OLE Automation
Reference=*\G{00020905-0000-0000-C000-000000000046}#8.1#0#D:\Program Files\Microsoft Office\Office\MSWORD9.OLB#Microsoft Word 9.0 Object Library
Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX
Form=frmMain.frm
Startup="frmMain"
ExeName32="Word.exe"
Command32=""
Name="prjWord"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="ATA"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
vansoft 2004-07-20
  • 打赏
  • 举报
回复
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmMain
BorderStyle = 3 'Fixed Dialog
Caption = "Word文档字数统计"
ClientHeight = 2895
ClientLeft = 45
ClientTop = 330
ClientWidth = 5295
Icon = "frmMain.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2895
ScaleWidth = 5295
StartUpPosition = 3 '窗口缺省
Begin MSComDlg.CommonDialog dlgFile
Left = 3480
Top = 2160
_ExtentX = 847
_ExtentY = 847
_Version = 393216
CancelError = -1 'True
DefaultExt = "*.doc"
DialogTitle = "打开"
Filter = "Word文档(*.doc)|*.doc"
End
Begin VB.Frame Frame1
Caption = "Word文档"
Height = 1095
Left = 0
TabIndex = 3
Top = 0
Width = 5295
Begin VB.CommandButton cmdOpen
Caption = "打开(&O)..."
Height = 375
Left = 3840
TabIndex = 4
Top = 600
Width = 1335
End
Begin VB.Label lblFileName
BackColor = &H00FFFFFF&
BorderStyle = 1 'Fixed Single
Height = 255
Left = 120
TabIndex = 5
Top = 240
Width = 5055
End
End
Begin VB.Frame Frame3
Caption = "定位"
Height = 1695
Left = 0
TabIndex = 2
Top = 1200
Width = 1695
Begin VB.CommandButton cmdAddress
Caption = "定位"
Enabled = 0 'False
Height = 375
Left = 240
TabIndex = 10
Top = 1200
Width = 1215
End
Begin VB.TextBox txtHang
Alignment = 1 'Right Justify
Height = 270
Left = 840
MaxLength = 2
TabIndex = 9
Text = "2"
Top = 720
Width = 615
End
Begin VB.TextBox txtPage
Alignment = 1 'Right Justify
Height = 270
Left = 840
MaxLength = 2
TabIndex = 8
Text = "1"
Top = 360
Width = 615
End
Begin VB.CheckBox chkHang
Caption = "行"
Height = 255
Left = 240
TabIndex = 7
Top = 720
Value = 1 'Checked
Width = 495
End
Begin VB.CheckBox chkPage
Caption = "页"
Height = 255
Left = 240
TabIndex = 6
Top = 360
Value = 1 'Checked
Width = 495
End
End
Begin VB.Frame Frame2
Caption = "统计信息"
Height = 1695
Left = 1800
TabIndex = 0
Top = 1200
Width = 3495
Begin VB.ListBox lstCount
Height = 1320
Left = 120
TabIndex = 1
Top = 240
Width = 3255
End
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Declare Function SetWindowPos& Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Dim objWord As New Word.Application
Dim cDialog As Word.Dialog

Private Sub cmdAddress_Click()
If chkPage.Value And chkHang.Value Then
objWord.Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=txtPage.Text
objWord.Selection.GoTo What:=wdGoToLine, Which:=wdGoToNext, Count:=txtHang.Text, Name:=""
Exit Sub
End If
If chkPage.Value Then
objWord.Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=txtPage.Text
Exit Sub
End If
If chkHang.Value Then
objWord.Selection.GoTo What:=wdGoToLine, Which:=wdGoToFirst, Count:=txtHang.Text, Name:=""
End If
End Sub

Private Sub cmdOpen_Click()
On Error GoTo cmdOpenERR:
dlgFile.ShowOpen
lblFileName.Caption = dlgFile.FileName
objWord.Documents.Open lblFileName.Caption, True
objWord.Visible = True
Set cDialog = objWord.Dialogs(wdDialogToolsWordCount)
lstCount.AddItem "pages:" & cDialog.pages
lstCount.AddItem "words:" & cDialog.Words
lstCount.AddItem "lines:" & cDialog.lines
lstCount.AddItem "CountFootnotes:" & cDialog.CountFootnotes
lstCount.AddItem "Characters:" & cDialog.Characters
lstCount.AddItem "CharactersIncludingSpaces:" & cDialog.CharactersIncludingSpaces
lstCount.AddItem "Paragraphs:" & cDialog.Paragraphs
cmdAddress.Enabled = True
Exit Sub
cmdOpenERR:

End Sub

Private Sub Form_Load()
Call SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
objWord.Documents.Close
objWord.Quit
Set objWord = Nothing
End Sub
flyingZFX 2004-07-19
  • 打赏
  • 举报
回复
第一问:

Sub Macro2()
'
' Macro2 Macro
' 宏在 2004-7-19 由 40666 录制
Dim i As Integer

For i = 1 To 100
Selection.TypeParagraph
Next i

End Sub

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\第二问:


完全可以,只要你的文档中存在文字,你就可以使用Range对象来定位。
flyingZFX 2004-07-19
  • 打赏
  • 举报
回复
什么都没有怎么移动光标呀,,,楼上的怎么实现的,贴出代码来!~~

问题二:
如果想定义,就自己加空格吧,没有别的办法了。
vansoft 2004-07-19
  • 打赏
  • 举报
回复
第二个问题可以用移动光标的方法来定位。

交流MSN:Van_flf@hotmail.com
jam021 2004-07-19
  • 打赏
  • 举报
回复
第一个问题已经解决.
第二个问题:我new了一个新的文档,里面还没有文字,能不能用类似坐标的方法来定位,并写上一些文字呢?飞老大,有办法吗?也请大家帮着看看,谢谢了!

2,462

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧