gpt4 book ai didi

vba - 如何在不误用样式的情况下跳过和执行 VBA 宏?

转载 作者:行者123 更新时间:2023-12-02 03:27:29 24 4
gpt4 key购买 nike

我有一些宏用于在 word 文档中应用样式,然后查找给定样式并将其替换为 HTML 标记。运行宏时出现错误:

"Run time error:5941 The requested member of collection does not exist."

例如:在下面的代码中,我应用了除Book_Title 样式之外的所有样式。

如何在运行宏时跳过丢失的样式?

Sub HTML_Conversion()
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Image")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "<p align=""center""><img src=""images\chapter_img.jpg"" alt=""""/></p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Book_Title")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = _
"<h1 class=""book-title"">^&</h1>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll



Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Half_Title")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""halftitle"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll



Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Indent_Para")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""indent"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll



Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("NonIndent_Para")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""noindent"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

正如您所说,我已经在我的宏中尝试过,但我遇到了同样的错误。

我的完整代码如下:

    Sub HTML_Conversion()

Dim sStyleName As String

sStyleName = "HTML_Start"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = _
"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?>^p<!DOCTYPE html>^p<html xml:lang=""en-US"" xmlns=""http://www.w3.org/1999/xhtml"">^p<head>^p<title></title>^p<link rel=""stylesheet"" type=""text/css"" href=""../css/epub.css""/>^p</head>^p<body>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End If

sStyleName = "Ack_title"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "<p class=""act-title"">^&</p>"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End If
sStyleName = "FigCaption"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "^p<figure>^p<img src=""images\chapter_img.jpg"" alt=""""/>^p<figcaption>^&</figcaption></figure>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End If
sStyleName = "TabCaption"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "<p class=""tabcaption"">^&</p>"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End If
sStyleName = "ListItem"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "*^13"
.Replacement.Text = "<li>^&</li>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End If
sStyleName = "OL_Start"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = ""
.Replacement.Text = "<ol>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End If
sStyleName = "OL_End"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = ""
.Replacement.Text = "</ol>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End If
sStyleName = "UL_Start"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = ""
.Replacement.Text = "<ul>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "UL_End"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = ""
.Replacement.Text = "</ul>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Image"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = ""
.Replacement.Text = "<p align=""center""><img src=""images\chapter_img.jpg"" alt=""""/></p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End If
sStyleName = "Book_Title"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = ""
.Replacement.Text = _
"<h1 class=""book-title"">^&</h1>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Half_Title"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""halftitle"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Indent_Para"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""indent"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "NonIndent_Para"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""noindent"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll



End If
sStyleName = "Book_Author"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""bookauthor"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Pub"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""pub"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Pub1"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""pub1"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Copyright"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""copyright"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Section"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting

With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""section"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Center_Para"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""center"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Block_Quote"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""blockquote"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Poem"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""poem"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Poem1"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""poem1"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Bibliography"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""bib"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Index"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""index"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Notes_Titles"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""nt"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If
sStyleName = "Notes"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""notes"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll



End If
sStyleName = "Right_Para"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""right"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll



End If
sStyleName = "Chapter_Title"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*^13"
.Replacement.Text = "<p class=""chtitle"">^&</p>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll



End If
sStyleName = "H1"
If IsValidDocumentStyle(ActiveDocument, sStyleName) Then

Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("sStyleName")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = "<h1>^&</h1>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


End If

MsgBox "HTML CONVERSION COMPLETED SUCCESSFULLY"

End Sub

最佳答案

基本错误处理:使用前检查样式是否有效!

有几种方法可以做到这一点,一种是循环所有样式以查看名称是否与可用样式之一匹配。另外,把它放在一个函数中,这样你就可以重用它。在我的示例中,该函数称为 IsValidDocumentStyle:

Option Explicit

Sub HTML_Conversion()

Dim sStyleName As String

sStyleName = "Book_Title"

If IsValidDocumentStyle(ActiveDocument, sStyleName) Then
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles(sStyleName)
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = _
"<h1 class=""book-title"">^&</h1>^p"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End If

End Sub

Function IsValidDocumentStyle(poDoc As Document, psStyleName As String) As Boolean
Dim oStyle As Style
Dim bReturn As Boolean

bReturn = False

For Each oStyle In poDoc.Styles
If oStyle.NameLocal = psStyleName Then
bReturn = True
Exit For
End If
Next

IsValidDocumentStyle = bReturn

Set oStyle = Nothing
End Function

编辑:

当尝试使用我的示例时,您将样式名称 "HTML_Start" 传递给 IsValidDocumentStyle 但随后使用文字字符串 "sStyleName" 作为 Selection.Find.Style = ActiveDocument.Styles("sStyleName") 行中的样式名称。

关于vba - 如何在不误用样式的情况下跳过和执行 VBA 宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29669869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com