使字符串等于命名范围所指的字符串? [英] Make a string equal to what a named range refers to?

查看:142
本文介绍了使字符串等于命名范围所指的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个叫做tempPrintArea
的命名范围,它指的是=A1:J59
我用VBA创建了它,范围变成了本地的。我不知道范围是否重要。



我使用这一行创建命名范围:

  wks.Names.Add Name:=tempPrintArea,RefersTo:=A1:J59

现在我想将一个字符串的值设置为A1:J59。我尝试了以下内容:

  Dim test As String 
test = Range(tempPrintArea)。RefersTo

但是我收到错误消息Method'Range'out of object'_Gloabl'failed



在这些代码行中可以更改哪些代码以使其正常工作?

解决方案

're use to = =A1:J59

代码不会将指向的命名范围创建为 A1 :J59 ,而代码使用文本 A1:J59创建命名范围。





  wks.Names.Add名称:=tempPrintArea,引用: = wks.Range(A1:J59)

然后

  Dim test As Str ing 
test = wks.Range(tempPrintArea)。Address(False,False)'返回A1:J59


I have a named range called tempPrintArea it refers to ="A1:J59" I created it with VBA and the scope became local. I don't know if the scope matters.

I used this line to create the named range:

wks.Names.Add Name:="tempPrintArea", RefersTo:="A1:J59"

Now I want to set the value of a string to "A1:J59". I've tried the following:

Dim test As String
test = Range("tempPrintArea").RefersTo

but I get the error message Method 'Range' out of object '_Gloabl' failed

What can I change in these code lines to get this working?

解决方案

When you're using

wks.Names.Add Name:="tempPrintArea", RefersTo:="A1:J59"

code doesn't create named range that refers to A1:J59, instead code creates named range with text "A1:J59".

For creating named range use this one instead:

wks.Names.Add Name:="tempPrintArea", RefersTo:=wks.Range("A1:J59")

and then

Dim test As String
test = wks.Range("tempPrintArea").Address(False, False) ' returns A1:J59

这篇关于使字符串等于命名范围所指的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆