- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我经常在工作中创建文档,在公司内部,由于我们使用的首字母缩写词和缩写词的数量,我们几乎拥有自己的语言。因此,我厌倦了在发布文档之前手动创建首字母缩写词和缩写表,并且快速的谷歌搜索发现了一个可以有效地为我完成它的宏。 (修改后的代码如下所示)
我修改了这个宏,以便将表格粘贴到原始文档中光标的位置(这可能不是 msot 有效的方式,但这是我能想到的最简单的方式,因为我不是 VBA 专家)。
从那时起,我意识到必须有一种简单的方法通过自动包含定义来进一步加快这个过程。我有一个 Excel 电子表格,第一列是首字母缩写词,第二列是它的定义。
到目前为止,我已经能够打开 excel 文档,但似乎无法获得将返回行号的搜索,因此使用它将旁边的定义单元格的内容复制到相应的定义部分Word 中的表格。
** 编辑 - 额外说明 **
当前宏搜索 word 文档并找到所有已使用的首字母缩略词,并将它们放在单独的 word 文档中的表格中。我想要做的是,然后搜索一个 excel 文件(预先存在的)以查找每个找到的首字母缩写词的定义,并将它们也添加到表中,或者如果它们是新的,则将其留空。最后,宏将该表复制回原始文档中。
此代码当前无法说明 .Find 函数未定义? (我暂时将代码分开以保持测试简单)
Dim objExcel As Object
Dim objWbk As Object
Dim objDoc As Document
Dim rngSearch As Range
Dim rngFound As Range
Set objDoc = ActiveDocument
Set objExcel = CreateObject("Excel.Application")
Set objWbk = objExcel.Workbooks.Open("P:\ENGINEERING\EL\Global Access\Abbreviations and Acronyms.xls")
objExcel.Visible = True
objWbk.Activate
With objExcel
With objWbk
Set rngSearch = objWbk.Range("A:A")
Set rngFound = rngSearch.Find(What:="AS345", LookIn:=xlValues, LookAt:=xlPart)
If rngFound Is Nothing Then
MsgBox "Not found"
Else
MsgBox rngFound.Row
End If
End With
End With
Err_Exit:
'clean up
Set BMRange = Nothing
Set objWbk = Nothing
objExcel.Visible = True
Set objExcel = Nothing
Set objDoc = Nothing
'MsgBox "The document has been updated"
Err_Handle:
If Err.Number = 429 Then 'excel not running; launch Excel
Set objExcel = CreateObject("Excel.Application")
Resume Next
ElseIf Err.Number <> 0 Then
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Err_Exit
End If
End Sub
Sub ExtractACRONYMSToNewDocument()
'=========================
'Macro created 2008 by Lene Fredborg, DocTools - www.thedoctools.com
'THIS MACRO IS COPYRIGHT. YOU ARE WELCOME TO USE THE MACRO BUT YOU MUST KEEP THE LINE ABOVE.
'YOU ARE NOT ALLOWED TO PUBLISH THE MACRO AS YOUR OWN, IN WHOLE OR IN PART.
'=========================
'Modified in 2014 by David Mason to place the acronym table in the original document
'=========================
Dim oDoc_Source As Document
Dim oDoc_Target As Document
Dim strListSep As String
Dim strAcronym As String
Dim strDef As String
Dim oTable As Table
Dim oRange As Range
Dim n As Long
Dim strAllFound As String
Dim Title As String
Dim Msg As String
Title = "Extract Acronyms to New Document"
'Show msg - stop if user does not click Yes
Msg = "This macro finds all words consisting of 3 or more " & _
"uppercase letters and extracts the words to a table " & _
"in a new document where you can add definitions." & vbCr & vbCr & _
"Do you want to continue?"
If MsgBox(Msg, vbYesNo + vbQuestion, Title) <> vbYes Then
Exit Sub
End If
Application.ScreenUpdating = False
'Find the list separator from international settings
'May be a comma or semicolon depending on the country
strListSep = Application.International(wdListSeparator)
'Start a string to be used for storing names of acronyms found
strAllFound = "#"
Set oDoc_Source = ActiveDocument
'Create new document for acronyms
Set oDoc_Target = Documents.Add
With oDoc_Target
'Make sure document is empty
.Range = ""
'Insert info in header - change date format as you wish
'.PageSetup.TopMargin = CentimetersToPoints(3)
'.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = _
' "Acronyms extracted from: " & oDoc_Source.FullName & vbCr & _
' "Created by: " & Application.UserName & vbCr & _
' "Creation date: " & Format(Date, "MMMM d, yyyy")
'Adjust the Normal style and Header style
With .Styles(wdStyleNormal)
.Font.Name = "Arial"
.Font.Size = 10
.ParagraphFormat.LeftIndent = 0
.ParagraphFormat.SpaceAfter = 6
End With
With .Styles(wdStyleHeader)
.Font.Size = 8
.ParagraphFormat.SpaceAfter = 0
End With
'Insert a table with room for acronym and definition
Set oTable = .Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=2)
With oTable
'Format the table a bit
'Insert headings
.Range.Style = wdStyleNormal
.AllowAutoFit = False
.Cell(1, 1).Range.Text = "Acronym"
.Cell(1, 2).Range.Text = "Definition"
'.Cell(1, 3).Range.Text = "Page"
'Set row as heading row
.Rows(1).HeadingFormat = True
.Rows(1).Range.Font.Bold = True
.PreferredWidthType = wdPreferredWidthPercent
.Columns(1).PreferredWidth = 20
.Columns(2).PreferredWidth = 70
'.Columns(3).PreferredWidth = 10
End With
End With
With oDoc_Source
Set oRange = .Range
n = 1 'used to count below
With oRange.Find
'Use wildcard search to find strings consisting of 3 or more uppercase letters
'Set the search conditions
'NOTE: If you want to find acronyms with e.g. 2 or more letters,
'change 3 to 2 in the line below
.Text = "<[A-Z]{3" & strListSep & "}>"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWildcards = True
'Perform the search
Do While .Execute
'Continue while found
strAcronym = oRange
'Insert in target doc
'If strAcronym is already in strAllFound, do not add again
If InStr(1, strAllFound, "#" & strAcronym & "#") = 0 Then
'Add new row in table from second acronym
If n > 1 Then oTable.Rows.Add
'Was not found before
strAllFound = strAllFound & strAcronym & "#"
'Insert in column 1 in oTable
'Compensate for heading row
With oTable
.Cell(n + 1, 1).Range.Text = strAcronym
'Insert page number in column 3
'.Cell(n + 1, 3).Range.Text = oRange.Information(wdActiveEndPageNumber)
End With
n = n + 1
End If
Loop
End With
End With
'Sort the acronyms alphabetically - skip if only 1 found
If n > 2 Then
With Selection
.Sort ExcludeHeader:=True, FieldNumber:="Column 1", SortFieldType _
:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending
'Go to start of document
.HomeKey (wdStory)
End With
End If
'Copy the whole table, switch to the source document and past
'in the table at the original selection location
Selection.WholeStory
Selection.Copy
oDoc_Source.Activate
Selection.Paste
'make the target document active and close it down without saving
oDoc_Target.Activate
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Application.ScreenUpdating = True
'If no acronyms found, show msg and close new document without saving
'Else keep open
If n = 1 Then
Msg = "No acronyms found."
oDoc_Target.Close SaveChanges:=wdDoNotSaveChanges
Else
Msg = "Finished extracting " & n - 1 & " acronymn(s) to a new document."
End If
MsgBox Msg, vbOKOnly, Title
'Clean up
Set oRange = Nothing
Set oDoc_Source = Nothing
Set oDoc_Target = Nothing
Set oTable = Nothing
End Sub
最佳答案
您只是缺少 Worksheet Object
.
还有With objExcel
可以省略,因为您已经通过了 Workbook Object
至objWbk
多变的。
With objWbk.Sheets("NameOfYourSheet")
Set rngSearch = .Range(.Range("A1"), .Range("A" & .Rows.Count).End(xlUp))
Set rngFound = rngSearch.Find(What:="AS345", After:=.Range("A1"), LookAt:=xlWhole)
If rngFound Is Nothing Then
MsgBox "Not found"
Else
MsgBox rngFound.Row
End If
End With
Late Binding
Excel,这应该工作:
With objWbk.Sheets("Sheet1")
Set rngSearch = .Range(.Range("A1"), .Range("A" & .Rows.Count).End(-4162))
Set rngFound = rngSearch.Find(What:="AS345", After:=.Range("A1"), LookAt:=1)
If rngFound Is Nothing Then
MsgBox "Not found"
Else
MsgBox rngFound.Row
End If
End With
xlUp
与它的等价常数
-4162
和
xlWhole
与
1
.
Immediate Window
- Ctrl+G
?
然后是您想要获得数字等价物的常数。
?xlUp
-4162
?xlWhole
1
?xlPart
2
关于vba - 自动 Excel 首字母缩写词查找和定义添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22833024/
我想看看我的表中使用了哪些月份。我可以获得 id 和名称(见下文)没问题,但我无法提取 abrv。我在使用 %b 之前已经完成了,但似乎无法在此处获得语法。我哪里错了? SELECT DIST
我记得 PaulP 展示了一个很酷的技巧来缩写重复的长 @specialized序列,但我找不到原来的帖子了。就像我有 trait Foo[@specialized(Int, Float, Doubl
此 C# 声明的等效 F# 声明是什么: 使用 NR = ICSharpCode.NRefactory; 最佳答案 F# 中的缩写可以应用于模块: module ES = Microsoft.FSha
我正在 emacs 中编辑 Mathematica 代码。 Mathematica 对希腊字母的明文表示看起来像 \[Alpha], \[Beta], \[Gamma], ... 我不介意输入这些,但
我从 GMT 偏移量(以秒为单位)开始,我想要相应时区的名称。我是说: let offset = -28800 let tz = TimeZone(secondsFromGMT: offset) le
我正在 emacs 中编辑 Mathematica 代码。 Mathematica 对希腊字母的明文表示看起来像 \[Alpha], \[Beta], \[Gamma], ... 我不介意输入这些,但
对于kubectl describe我可以简写几类资源,例如: po/xxx -> pods/xxx rs/xxx -> replicasets/xxx 我在哪里可以找到完整列表? 我正在尝试查找部署
当 id 是我们对目标的全部了解时,将 UUID 缩写为在用户界面中的按钮中使用的好方法是什么? GitHub 似乎通过从开头取 7 个字符来缩写提交 ID。例如 b1310ce6bc3cc932ce
这个 C/C++ 简化测试用例: int x = ~~~; const double s = 1.0 / x; const double r = 1.0 - x * s; assert(r >= 0)
如果我有一个具有许多共享相同属性约束的属性的类,如下所示: class myClass { String thisString String thatString String
我正在研究 Java Card (SIM),并且正在使用 OTA 技术。有些表达方式我还没有一个很好的定义。 例如,当我在 SIM(用户身份模块)上加载小程序时,我使用 BIP 或 SMS。我知道短信
这个问题与这个问题是同一个问题(但是对于log4j2): log4j: abbreviate/shorten package names 最佳答案 这非常简单,记录在 http://logging.a
这个 C/C++ 简化测试用例: int x = ~~~; const double s = 1.0 / x; const double r = 1.0 - x * s; assert(r >= 0)
我刚刚查看了下面列出的 gcc-arm-none-eabi 编译器二进制文件,但我真的不知道所有使用的缩写。我想知道哪个二进制文件是预处理器、链接器、编译器等等... $ ls /opt/gcc-ar
缩写 UBER 是什么意思?我知道 UBER 是 BouncyCaSTLe-Keystore 等,但我不知道缩写是什么意思。 谢谢 最佳答案 我认为这是对德语单词“Über”(over 或 super
代码应该打印用户的姓名缩写,但代码有一个错误,而是打印出整个名称,每个字母之间有空格。我知道错误存在于 for 循环中,但我不知道如何调试这个问题。建议? int main(void) { prin
当我尝试在 for 循环中使用“i < n”时,出现错误(准确地说是 4)。如果我把它拿出来,我就会陷入无限循环。我似乎也无法运行 if 语句。对我可以改进的地方有什么想法吗? int main()
有没有办法缩写以下内容? if ($chk == 1 || $chk == 3 || $chk == 5 || $chk == 7){ do some stuff } 谢谢。 最佳答案 if (in_
如何在使用 log4j 生成的日志中缩写/缩短包名称。即,我想要 c.l.a.l.MyClass 而不是 com.longpackage.anotherpackage.lastpackage.MyCl
我正在使用 ReSharper 并试图遵守它的默认规则。 在我的部分代码中,我需要将字符串属性更改为 PascalCase。 我尝试了多种方法,但找不到一种适用于所有大写缩写的方法。 前任: MPSU
我是一名优秀的程序员,十分优秀!