- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在附加的代码中,我正在搜索关键字,然后创建一个包含文件名、工作表、单元格、数据等行条目的新工作表。我试图将超链接(感谢 Siddharth Rout )放入“单元格”列(即该程序中的“C”列)中找到的关键字。当进入新的 Private Sub
时,创建的超链接消失,我从搜索的工作簿中提取行数据,导致新创建的文件不包含任何超链接。您能帮我维护新创建的文件中的超链接吗?谢谢。
代码如下:
Sub SearchFolders()
'UpdatebySUPERtoolsforExcel2016
Dim xFso As Object
Dim xFld As Object
Dim xStrSearch As String
Dim xStrPath As String
Dim xStrFile As String
Dim xOut As Worksheet
Dim xWb As Workbook
Dim xWk As Worksheet
Dim xRow As Long
Dim xFound As Range
Dim xStrAddress As String
Dim xFileDialog As FileDialog
Dim xUpdate As Boolean
Dim xCount As Long
On Error GoTo ErrHandler
Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
xFileDialog.AllowMultiSelect = False
xFileDialog.Title = "Select a forlder"
If xFileDialog.Show = -1 Then
xStrPath = xFileDialog.SelectedItems(1)
End If
If xStrPath = "" Then Exit Sub
xStrSearch = "failed"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Create the report sheet at first position then name it "Summary"
Dim wsReport As Worksheet, rCellwsReport As Range
Set wsReport = ThisWorkbook.Sheets.Add(Before:=ThisWorkbook.Sheets(1))
wsReport.Name = "Summary"
Set rCellwsReport = wsReport.Cells(2, 2)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
xUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
Set xOut = wsReport
xRow = 1
With xOut
.Cells(xRow, 1) = "Workbook"
.Cells(xRow, 2) = "Worksheet"
.Cells(xRow, 3) = "Cell"
.Cells(xRow, 4) = "Test"
.Cells(xRow, 5) = "Limit Low"
.Cells(xRow, 6) = "Limit High"
.Cells(xRow, 7) = "Measured"
.Cells(xRow, 8) = "Unit"
.Cells(xRow, 9) = "Status"
Set xFso = CreateObject("Scripting.FileSystemObject")
Set xFld = xFso.GetFolder(xStrPath)
xStrFile = Dir(xStrPath & "\*.xlsx")
Do While xStrFile <> ""
Set xWb = Workbooks.Open(Filename:=xStrPath & "\" & xStrFile, UpdateLinks:=0, ReadOnly:=True, AddToMRU:=False)
For Each xWk In xWb.Worksheets
Set xFound = xWk.UsedRange.Find(xStrSearch, LookIn:=xlValues)
If Not xFound Is Nothing Then
xStrAddress = xFound.Address
End If
Do
If xFound Is Nothing Then
Exit Do
Else
shName = xWk.Name
If InStr(1, shName, " ") Then shName = "'" & shName & "'"
xCount = xCount + 1
xRow = xRow + 1
.Cells(xRow, 1) = xWb.Name
.Cells(xRow, 2) = xWk.Name
.Cells(xRow, 3) = xFound.Address
Range("C" & xRow).Formula = "=HYPERLINK(" & Chr(34) & "[" & _
xWb.FullName & _
"]" & _
shName & _
"!" & _
xFound.Address & _
Chr(34) & "," & Chr(34) & _
xFound.Address & Chr(34) & ")"
WriteDetails rCellwsReport, xFound
End If
Set xFound = xWk.Cells.FindNext(After:=xFound)
Loop While xStrAddress <> xFound.Address
Next
xWb.Close (False)
xStrFile = Dir
Loop
.Columns("A:I").EntireColumn.AutoFit
.Range("A1:A" & xCount + 1).Rows.EntireRow.AutoFit
End With
MsgBox xCount & "cells have been found", , "SUPERtools for Excel"
ExitHandler:
Set xOut = Nothing
Set xWk = Nothing
Set xWb = Nothing
Set xFld = Nothing
Set xFso = Nothing
Application.ScreenUpdating = xUpdate
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
Private Sub WriteDetails(ByRef xReceiver As Range, ByRef xDonor As Range)
xReceiver.Value = xDonor.Parent.Name
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copy the row of the Donor to the receiver starting from column D.
' Since you want to preserve formats, we use the .Copy method
xDonor.EntireRow.Resize(, 100).Copy xReceiver.Offset(, 2)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set xReceiver = xReceiver.Offset(1)
End Sub
最佳答案
如评论中所述,限定您的 Range
语句,以便它不会将超链接放入您随后关闭而不保存的工作簿中。
即改变
Range("C" & xRow).Formula = "=HYPERLINK(" & Chr(34) & "[" & _
至
.Range("C" & xRow).Formula = "=HYPERLINK(" & Chr(34) & "[" & _
<小时/>
从代码中获取相关行:
'******************************************
'*** Set xOut so that it refers to wsReport
Set xOut = wsReport
'******************************************
xRow = 1
'******************************************
'*** Begin a With block so that "." means "xOut."
With xOut
'******************************************
.Cells(xRow, 1) = "Workbook"
.Cells(xRow, 2) = "Worksheet"
.Cells(xRow, 3) = "Cell"
.Cells(xRow, 4) = "Test"
.Cells(xRow, 5) = "Limit Low"
.Cells(xRow, 6) = "Limit High"
.Cells(xRow, 7) = "Measured"
.Cells(xRow, 8) = "Unit"
.Cells(xRow, 9) = "Status"
Set xFso = CreateObject("Scripting.FileSystemObject")
Set xFld = xFso.GetFolder(xStrPath)
xStrFile = Dir(xStrPath & "\*.xlsx")
Do While xStrFile <> ""
'******************************************
'*** Open a workbook, and make it the ActiveWorkbook and one of its sheets
'*** the ActiveSheet
Set xWb = Workbooks.Open(Filename:=xStrPath & "\" & xStrFile, UpdateLinks:=0, ReadOnly:=True, AddToMRU:=False)
'******************************************
For Each xWk In xWb.Worksheets
Set xFound = xWk.UsedRange.Find(xStrSearch, LookIn:=xlValues)
If Not xFound Is Nothing Then
xStrAddress = xFound.Address
End If
Do
If xFound Is Nothing Then
Exit Do
Else
shName = xWk.Name
If InStr(1, shName, " ") Then shName = "'" & shName & "'"
xCount = xCount + 1
xRow = xRow + 1
'******************************************
'*** Write information to column A of the report
.Cells(xRow, 1) = xWb.Name
'******************************************
'******************************************
'*** Write information to column B of the report
.Cells(xRow, 2) = xWk.Name
'******************************************
'******************************************
'*** Write information to column C of the report
.Cells(xRow, 3) = xFound.Address
'******************************************
'******************************************
'*** Write information to column C of the ActiveWorkbook's ActiveSheet
'*** (because "Range" is unqualified)
'*** If this was ".Range" it would write information to column C of the report
Range("C" & xRow).Formula = "=HYPERLINK(" & Chr(34) & "[" & _
xWb.FullName & _
"]" & _
shName & _
"!" & _
xFound.Address & _
Chr(34) & "," & Chr(34) & _
xFound.Address & Chr(34) & ")"
'******************************************
WriteDetails rCellwsReport, xFound
End If
Set xFound = xWk.Cells.FindNext(After:=xFound)
Loop While xStrAddress <> xFound.Address
Next
'******************************************
'*** Close the ActiveWorkbook (which has had hyperlinks added to it)
'*** without saving
xWb.Close (False)
'******************************************
<小时/>
我告诉您限定范围
的“官方”(可能是“可信”)来源可以在 MSDN documentation 中找到。对于 Range
对象,它(部分)表示:
When it’s used without an object qualifier (an object to the left of the period), the Range property returns a range on the active sheet.
关于excel - 进入新的私有(private)子目录时生成的超链接消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44376510/
据我所知,在 C# 中,所有字段默认都是私有(private)的,如果没有另外标记的话。 class Foo { private string bar; } class Foo { strin
这个问题在这里已经有了答案: Why is it allowed to access Java private fields via reflection? (7 个答案) 关闭 6 年前。 使用反
在 C#(和许多其他语言)中,访问相同类型的其他实例的私有(private)字段是完全合法的。例如: public class Foo { private bool aBool; pu
使用私有(private)方法通过将一些决策点重构为单独的方法来降低 CC 会降低实际方法的 CC 并易于阅读,但不会减少在测试中获得完整分支覆盖的工作量。 这合理吗?你有什么现场经验? 最佳答案 好
在下面的例子中,模块outer有一个私有(private)类型Private和一个私有(private)内部模块inner。 inner 能够访问Private(因为子模块可以访问其父级的私有(pri
class Person def one @var = 99 self.two end private def two p @var end end p=P
我在 Azure 中创建了 VNET。我放入了一个子集 Azure Private Link,它在 VNET 之外和另一台虚拟机中调用 Azure Function。 当我尝试通过专用 IP 调用专用
我在 Azure 中创建了 VNET。我放入了一个子集 Azure Private Link,它在 VNET 之外和另一台虚拟机中调用 Azure Function。 当我尝试通过专用 IP 调用专用
我正在尝试获得良好的 Ruby 编码风格。为防止意外调用具有相同名称的局部变量,我总是在适当的地方使用 self.。但是现在我偶然发现了这个: class MyClass "method" a
今天遇到一个案例类构造函数的奇怪问题。我想将构造函数设为私有(private),看来这不是问题。所以我已经在我的一个项目中尝试过它并且它有效。但在另一个项目中,我可以调用私有(private)构造函数
我想坚持使用记录,并且不想返回对象。所以我想知道是否可以将记录的字段设置为私有(private)?或者创建记录的私有(private)成员。其他具体类型(例如可区分联合)怎么样? 或者,这个要求是否违
我正在通过 Flickr API 进行经过身份验证的调用来访问照片。但我只得到我的公开照片,而没有任何私有(private)照片。 下面给出的是我正在使用的代码, Flickr f; Request
这两个类的行为不同;原因似乎与使用 private[this] 声明而不是 private 有关。有人可以解释一下为什么吗? 私有(private): class Person( private
在 private 中的 1000 秒 private 之后,我想到可能不需要它 public class Outer { private static class Inner { // yo
我有以下代码: class C { private enum E { // ... } } private extension C { func f(e: E)
OOP 语言中是否有object-private 的概念??我的意思是比经典的私有(private)访问限制更多? Private (or class-private) restricts the a
swift 3.0 我知道fileprivate访问级别修饰符将函数/属性的使用限制在声明它的源文件和 private - 仅限于声明的词法范围。但似乎这条规则不适用于扩展。例如。此代码有效: cla
即将推出的 Delphi 版本中启用该功能的功能怎么样? 也许它可能是一个编译器开关,促进所有 ** private **s to ** strict private **小号。 ... 或者它可能是
我可以通过将函数放入类的私有(private)扩展中来创建私有(private)函数,而不是通过不断调用 private func functionName(){} 来创建新的私有(private)函
部署专用端点并需要专用 IP 地址作为输出,但似乎无法正确获取值查询。下面的结果是“模板输出'主机名'无效:语言表达式属性|'privateIPAddress'具有无效的数组索引..(代码:Deplo
我是一名优秀的程序员,十分优秀!