错误1004“应用程序定义的错误或对象定义的错误”由Names(“NamedRange”)抛出.RefersToRange [英] Error 1004 "Application-defined or Object-defined error" being thrown by Names("NamedRange").RefersToRange

查看:270
本文介绍了错误1004“应用程序定义的错误或对象定义的错误”由Names(“NamedRange”)抛出.RefersToRange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我无法弄清楚导致以下问题的原因,所以欢迎任何输入。


<我写了一个VB代码,在我的机器上工作得非常好(我知道程序员通常这么说,但我这次真的是指它),但是在另一台机器上它会抛出'1004'错误。我注意到的两件事情在机器之间有所不同:
mine有Office 2013并且是英文的,但其他的有Office 2010并且是葡萄牙文。


这里是我正在做什么来创建命名范围:

 ActiveWorkbook.Names.Add Name:=" NamedRange1",RefersTo:= " = OFFSET(MySheet!$ B $ 1,0,0,COUNTA(MySheet!$ B:$ B),1)" 

稍后,我正在尝试通过这样做来访问这个命名范围:

 ThisWorkbook.ArraySubstitute2(sht.range(" B"& i),ActiveWorkbook .Names(" NamedRange1")。RefersToRange,ActiveWorkbook.Names(" NamedRange2")。RefersToRange)

'ArraySubstitute2'是一个公共静态函数,这里是它的签名:

公共静态函数ArraySubstitute2(OrigStr As String,Rng1 As range,rng2 As range)As String 

那么,什么我在这里不见了?有人可以提供建议吗?



编辑1 :" MySheet"是这个确切名称下的现有工作表,其中包含刚从数据库中提取的参考数据。


编辑2:  VB代码在所有使用英语的计算机上都能正常工作Office 2013.但是,如果我在具有PT BR Office 2010的计算机上执行相同的文件,则会抛出错误1004。



提前致谢!

解决方案

DHNunes,

re:名称问题



我的猜测是"MySheet!"在葡萄牙,该名称下不存在工作表。



'---

Jim Cone

https://goo.gl/IUQUN2


Hi all,

I'm having trouble trying to figure out what's causing the following issue, so any input is welcome.

I wrote a VB code that works perfectly fine on my machine (I know that programmers usually say this, but I really mean it this time hehe), but on another machine it's throwing the '1004' error. The two things I've noticed that are different between the machines: mine has Office 2013 and is in English, but the others have Office 2010 and are in Portuguese.

Here's what I'm doing to create the named range:

ActiveWorkbook.Names.Add Name:="NamedRange1", RefersTo:="=OFFSET(MySheet!$B$1,0,0,COUNTA(MySheet!$B:$B),1)"

Later, I'm trying to access this named range by doing this:

ThisWorkbook.ArraySubstitute2(sht.range("B" & i), ActiveWorkbook.Names("NamedRange1").RefersToRange, ActiveWorkbook.Names("NamedRange2").RefersToRange)

The 'ArraySubstitute2' is a public static function, here's its signature:

Public Static Function ArraySubstitute2(OrigStr As String, Rng1 As range, rng2 As range) As String

So, what am I missing here? Can someone please advise?

Edit 1: "MySheet" is an existing worksheet under this exact name that holds reference data just extracted from DB.

Edit 2: The VB code works fine on all computers using English Office 2013. But if I execute the same file on a machine with PT BR Office 2010 it throws the error 1004.

Thanks in advance!

解决方案

DHNunes,
re: Name problem

My guess is that the "MySheet!" worksheet does not exist under that name in Portugal.

'---
Jim Cone
https://goo.gl/IUQUN2


这篇关于错误1004“应用程序定义的错误或对象定义的错误”由Names(“NamedRange”)抛出.RefersToRange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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