我正在尝试用VBA制作一个Solidworks宏。
其想法是从某个文件夹导入DXF文件。
第一阶段:使用Dir方法扫描所有现有的DXFfile (完成)
第二阶段:使用.AddItem filename将文件名添加到组合框(完成)
第三阶段:从模块获取选定组合框的值(问题)
下面是我的粗略代码
'Within UserForm
Public folderpath, filepath, FileName as String
Public fullpath as String
Private Sub UserForm_Initialize()
folderpath = "insert path"
filepath = folderpath & "*.dxf"
FileName = Dir(filepath)
Do Until FileName = ""
With ComboBox1
.AddItem FileName
End With
FileName = Dir
Loop
'The FileName was added to ComboBox1 successfully
End Sub
Private Sub ComboBox1_Change()
fullpath = folderpath & ComboBox1.Value
'It returns the fullpath no problem
Debug.Print fullpath
End Sub
问题来了
'Import Module
Sub import()
Dim UserForm1 as New Form
'Here I tried to test if the fullpath is successfully called within the module, but it returns nothing
Debug.Print Form.fullpath
'Ignore the SW codes
Set swApp = _
Application.SldWorks
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("FRONT", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Dim myFeature As Object
Set myFeature = Part.FeatureManager.InsertDwgOrDxfFile(Form.fullpath)
End Sub
我声明了all path被设置为Public,它应该对所有模块都是可读的。它可以与TextBox完美配合,但不能与ListBox或ComboBox配合使用。有什么想法吗?
发布于 2018-06-06 08:59:57
我刚刚发现在两个不同的模块中调用相同的UserForm会在后面的模块中返回空,我修复了这个问题,它成功地调用了ComboBox.Value。
很抱歉发了垃圾帖子。我想我终究还是自己弄明白了。
https://stackoverflow.com/questions/50710752
复制相似问题