|
楼主 |
发表于 2020-1-31 11:41
|
显示全部楼层
出现了一个新问题,我测试的时候,使用了一个空白文档,三个书签均无内容,vba报错。修改后还是不行,请各位专家帮忙看看。
Private Sub UserForm_Initialize()
Dim BMRange1 As Range, BMRange2 As Range, BMRange3 As Range
Set BMRange1 = ActiveDocument.Bookmarks("title").Range '将书签内容赋予变量
If IsNull(BMRange1.Text) = True Then
Set BMRange1 = Empty '如果指定书签内容为空,则向其赋一个长度为空白的值
ActiveDocument.Bookmarks.Add "title", BMRange1 '重新生成书签内容
End If
Set BMRange2 = ActiveDocument.Bookmarks("company").Range '将书签内容赋予变量
If IsNull(BMRange2.Text) = True Then
Set BMRange2 = Empty '如果指定书签内容为空,则向其赋一个长度为空白的值
ActiveDocument.Bookmarks.Add "company", BMRange2 '重新生成书签内容
End If
Set BMRange3 = ActiveDocument.Bookmarks("project").Range '将书签内容赋予变量
If IsNull(BMRange3.Text) = True Then
Set BMRange3 = Empty '如果指定书签内容为空,则向其赋一个长度为空白的值
ActiveDocument.Bookmarks.Add "project", BMRange3 '重新生成书签内容
End If
'Set BMRange1 = ActiveDocument.Bookmarks("title").Range '将书签内容赋予变量
'Set BMRange2 = ActiveDocument.Bookmarks("company").Range '将书签内容赋予变量
'Set BMRange3 = ActiveDocument.Bookmarks("project").Range '将书签内容赋予变量
TextBox1.Value = BMRange1.Text '将书签变量的内容赋予文本框
TextBox2.Value = BMRange2.Text '将书签变量的内容赋予文本框
TextBox3.Value = BMRange3.Text '将书签变量的内容赋予文本框
End Sub
Private Sub CommandButton1_Click()
Dim BMRange1 As Range, BMRange2 As Range, BMRange3 As Range
'Set BMRange1 = ActiveDocument.Bookmarks("title").Range '将书签内容赋予变量
'Set BMRange2 = ActiveDocument.Bookmarks("company").Range '将书签内容赋予变量
'Set BMRange3 = ActiveDocument.Bookmarks("project").Range '将书签内容赋予变量
Set BMRange1 = ActiveDocument.Bookmarks("title").Range '将书签内容赋予变量
If IsNull(BMRange1.Text) = True Then
Set BMRange1 = Empty '如果指定书签内容为空,则向其赋一个长度为空白的值
ActiveDocument.Bookmarks.Add "title", BMRange1 '重新生成书签内容
End If
Set BMRange2 = ActiveDocument.Bookmarks("company").Range '将书签内容赋予变量
If IsNull(BMRange2.Text) = True Then
Set BMRange2 = Empty '如果指定书签内容为空,则向其赋一个长度为空白的值
ActiveDocument.Bookmarks.Add "company", BMRange2 '重新生成书签内容
End If
Set BMRange3 = ActiveDocument.Bookmarks("project").Range '将书签内容赋予变量
If IsNull(BMRange3.Text) = True Then
Set BMRange3 = Empty '如果指定书签内容为空,则向其赋一个长度为空白的值
ActiveDocument.Bookmarks.Add "project", BMRange3 '重新生成书签内容
End If
BMRange1 = TextBox1.Value '将文本框的内容赋予书签变量
BMRange2 = TextBox2.Value '将文本框的内容赋予书签变量
BMRange3 = TextBox3.Value '将文本框的内容赋予书签变量
ActiveDocument.Bookmarks.Add "title", BMRange1 '重新生成书签内容
ActiveDocument.Bookmarks.Add "company", BMRange2 '重新生成书签内容
ActiveDocument.Bookmarks.Add "project", BMRange3 '重新生成书签内容
Unload UserForm1
End Sub
|
|