运行时错误50012-方法“导出"(Export).'VBComponent'的错误失败 [英] run-time error 50012 - Method "Export" of object 'VBComponent' failed error

查看:34
本文介绍了运行时错误50012-方法“导出"(Export).'VBComponent'的错误失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码可以将模块和用户表单从一个工作簿转移到可以在多个系统上工作的另一个工作簿.但是,我有2个用户失败,并显示错误

I have a piece of code to transfer a module and a user form from one workbook to another that works on multiple systems. However, I have 2 users that it fails with the error

运行时错误'50012'-对象'VBComponent'的方法'导出'失败"

"Run-Time error '50012' - Method 'Export' of object 'VBComponent' failed"

代码如下:

Public Sub TransferModule2()
Const MODULE_NAME    As String = "Module5"         ' Name of the module to transfer
Const UserForm As String = "UserForm1"
Dim ID As String
ID = Environ("USERNAME")

Dim TEMPFILE As String
TEMPFILE = "C:/Users/" & ID & "/Desktop/Modul.bas" ' temp textfile
TEMPFILE2 = "UserForm.frm"
   
   ' On Error Resume Next
   '**Create new workbook
   
   '** export the module to a textfile
   Workbooks(Module4.GetBook3).VBProject.VBComponents(MODULE_NAME).Export fileName:=TEMPFILE
  
   'import the module to the new workbook
   Workbooks(TemplateBook).VBProject.VBComponents.Import fileName:=TEMPFILE
   
   Workbooks(Module4.GetBook3).VBProject.VBComponents(UserForm).Export fileName:=TEMPFILE2
    Workbooks(TemplateBook).VBProject.VBComponents.Import fileName:=TEMPFILE2
  
   'kill the textfile
   Kill TEMPFILE
   Kill TEMPFILE2
End Sub

该错误在第一个导出代码上发生.我已经在这些计算机上启用了Visual Basic对象项目模式,它仍然会失败,但是在任何其他计算机上都没有问题.计算机与我的成像时间完全相同,并且文件位于单个位置,因此没有代码修改.我们正在运行具有完全相同更新的完全相同版本的Office.

The error occurs on the first export code. I have enabled Visual Basic Object Project Mode on these computers and it still fails, but has no issues on any other computer. The computers were imaged at the exact same time as mine, and the file is in a single location so there are no code modifications. We are running the exact same version of Office with the exact same updates.

与不是引用库或版本控制问题的导出对象语句有什么冲突?

What could be conflicting with this export object statement that isn't a reference library or a versioning issue?

推荐答案

事实证明,所讨论的两个用户的登录ID与桌面所在位置的ID不同.我不确定为什么IT会这样做,但是事实证明这是TEMPFILE路径中的位置问题.我不知道为什么我没有抓住它,它让我可以使用UserForm传输上的默认路径,好像我看上去更深了,我会看到这就是解决方案.

It turns out that the two users in question have different ID's for their login than the location where their desktop lives. I'm unsure why IT did this, but it turns out this was a location issue within the TEMPFILE path. I don't know why I didn't catch that it let me use the default path on the UserForm transfer, as if I had of looked deeper I would have seen that was the solution.

这篇关于运行时错误50012-方法“导出"(Export).'VBComponent'的错误失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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