简体   繁体   English

VBA脚本中的excel命名范围

[英]excel named ranges in VBA script

I am using 我在用

Worksheets("Named_ranges").Range("A1").ListNames

to write the list of named ranges in the Named_ranges sheet but the result is like Named_ranges表中写入命名范围的列表,但结果类似于

is_pp4 = Checklist!$D$28 

so to show the contents of =Checklist!$D$28 , I need to press F2 and then Enter. 所以要显示=Checklist!$D$28 ,我需要按F2,然后按Enter。 I have tried to search and replace the = with = as suggested on other answers and it works when executed from Excel interface but it has to be done automatically with VBA script and from there the search and replace method does not solve the problem. 我已经尝试按照其他答案中的建议将=替换为=,并且可以从Excel界面执行,但必须使用VBA脚本自动完成,并且从那里搜索和替换方法无法解决问题。 The Calculations options are set to Automatic. “计算”选项设置为“自动”。

This should do what you describe: 这应该按照您的描述进行:

With Worksheets("Named_ranges").Range("A1")
    .ListNames
    .CurrentRegion.Numberformat = "General"
    .CurrentRegion.Replace "=", "=", xlPart
End With

Edit: I think there may be a timing issue with ListNames so it may be better to loop: 编辑:我认为ListNames可能存在计时问题,因此循环可能会更好:

Dim n As Long
Dim arrData()
With ActiveWorkbook.Names
ReDim arrData(1 To .Count, 1 To 2)
For n = 1 To .Count
    arrData(n, 1) = .Item(n).Name
    arrData(n, 2) = .Item(n).RefersTo
Next n
End With
Worksheets("Named_ranges").Range("A1").Resize(UBound(arrData, 1), 2).Value = arrData

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM