我在VBA编程中运行程序,弹出无效外部过程,求大神指点,怎么解决?
程序如下:DimT_stringAsString'临时变量DimT_longAsLong'临时变量DimCass_NumAsStringDimCass_NameAsStr...
程序如下:Dim T_string As String '临时变量
Dim T_long As Long '临时变量
Dim Cass_Num As String
Dim Cass_Name As String '读数据段数序
Dim Cass_y As Double '读数据段Y
Dim Cass_x As Double '读数据段X
Dim Cass_h As Double '读数据段H
Dim Cass_xyh(2) As Double 'vba,格式坐标
Dim Cass_old_xyh() As Double 'vba,格式坐标
Dim Cass_old_x As Double '旧Cass_xyh(0)
Dim Cass_old_y As Double '旧Cass_xyh(1)
My_filename = Open_File() '打开文件
If My_filename = "" Then Exit Sub
Do Until EOF(1) '文件读取循环
If Me.checkBox_turn = True Then
Input #1, Cass_Num, Cass_Name, Cass_xyh(1), Cass_xyh(0), Cass_xyh(2) 'DAT格式
Else
Input #1, Cass_Num, Cass_Name, Cass_xyh(0), Cass_xyh(1), Cass_xyh(2) 'DAT格式
End If
Cass_old_x = Cass_xyh(0)
Cass_old_y = Cass_xyh(1)
If Me.checkbox_h = Ture Then '显示高程
ThisDrawing.ActiveLayer = Layer_h '当前层
Set Text = ThisDrawing.ModelSpace.AddText(Format(Cass_xyh(2), Zero), Cass_xyh, Me.Textbox_Text_H) '生成文本对象
Cass_xyh(0) = Cass_old_x
End If
If Me.checkbox_Num = Ture Then '显示数序
ThisDrawing.ActiveLayer = Layer_Num '当前层
Cass_xyh(1) = Cass_xyh(1) - Text_2H '位置
Set Text = ThisDrawing.ModelSpace.AddText(Cass_Num, Cass_xyh, Me.Textbox_Text_H)
Cass_xyh(1) = Cass_old_y
End If
If Me.checkbox_point = Ture Then
ThisDrawing.ActiveLayer = Layer_Point '当前层
If Me.optionbutton_h_0 = Ture Then Cass_xyh(2) = 0
Set Point = ThisDrawing.ModelSpace.AddPoint(Cass_xyh)
End If
Loop '文件读取循环
Private Function Open_File() As String
Dim My_filename As String
CommonDialog1.Flags = cd10FNHideReadOnly
CommonDialog1.DialogTitle = "Open 打开CASS(*.dat)数据格式文件"
Me.CommonDialog1.Filter = "数据文件(*.dat)|*.DAT|文件文本(*.dat)|*.TXT|所有文件 (*.*)|*.*|"
Me.CommonDialog1.FilterIndex = 1
'On Error Goto out1'
Me.CommonDialog1.FileName = ""
Me.CommonDialog1.ShowOpen
My_filename = Me.CommonDialog1.FileName
If My_filename = "" Or My_filename = "*.dat" Or My_filename = "*.txt" Or My_filename <> "Empty" Then
Open_File = My_filename
End If
End Function
指着Open_File()这里 展开
Dim T_long As Long '临时变量
Dim Cass_Num As String
Dim Cass_Name As String '读数据段数序
Dim Cass_y As Double '读数据段Y
Dim Cass_x As Double '读数据段X
Dim Cass_h As Double '读数据段H
Dim Cass_xyh(2) As Double 'vba,格式坐标
Dim Cass_old_xyh() As Double 'vba,格式坐标
Dim Cass_old_x As Double '旧Cass_xyh(0)
Dim Cass_old_y As Double '旧Cass_xyh(1)
My_filename = Open_File() '打开文件
If My_filename = "" Then Exit Sub
Do Until EOF(1) '文件读取循环
If Me.checkBox_turn = True Then
Input #1, Cass_Num, Cass_Name, Cass_xyh(1), Cass_xyh(0), Cass_xyh(2) 'DAT格式
Else
Input #1, Cass_Num, Cass_Name, Cass_xyh(0), Cass_xyh(1), Cass_xyh(2) 'DAT格式
End If
Cass_old_x = Cass_xyh(0)
Cass_old_y = Cass_xyh(1)
If Me.checkbox_h = Ture Then '显示高程
ThisDrawing.ActiveLayer = Layer_h '当前层
Set Text = ThisDrawing.ModelSpace.AddText(Format(Cass_xyh(2), Zero), Cass_xyh, Me.Textbox_Text_H) '生成文本对象
Cass_xyh(0) = Cass_old_x
End If
If Me.checkbox_Num = Ture Then '显示数序
ThisDrawing.ActiveLayer = Layer_Num '当前层
Cass_xyh(1) = Cass_xyh(1) - Text_2H '位置
Set Text = ThisDrawing.ModelSpace.AddText(Cass_Num, Cass_xyh, Me.Textbox_Text_H)
Cass_xyh(1) = Cass_old_y
End If
If Me.checkbox_point = Ture Then
ThisDrawing.ActiveLayer = Layer_Point '当前层
If Me.optionbutton_h_0 = Ture Then Cass_xyh(2) = 0
Set Point = ThisDrawing.ModelSpace.AddPoint(Cass_xyh)
End If
Loop '文件读取循环
Private Function Open_File() As String
Dim My_filename As String
CommonDialog1.Flags = cd10FNHideReadOnly
CommonDialog1.DialogTitle = "Open 打开CASS(*.dat)数据格式文件"
Me.CommonDialog1.Filter = "数据文件(*.dat)|*.DAT|文件文本(*.dat)|*.TXT|所有文件 (*.*)|*.*|"
Me.CommonDialog1.FilterIndex = 1
'On Error Goto out1'
Me.CommonDialog1.FileName = ""
Me.CommonDialog1.ShowOpen
My_filename = Me.CommonDialog1.FileName
If My_filename = "" Or My_filename = "*.dat" Or My_filename = "*.txt" Or My_filename <> "Empty" Then
Open_File = My_filename
End If
End Function
指着Open_File()这里 展开
2个回答
展开全部
CommonDialog1 是在VB中用的,VBA 请参考如下代码,然后自己修改
Sub 对话框()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
'单选择
.Filters.Clear
'清除文件过滤器
.Filters.Add "Excel Files", "*.xls;*.xlw"
.Filters.Add "All Files", "*.*"
'设置两个文件过滤器
If .Show = -1 Then
'FileDialog 对象的 Show 方法显示对话框,并且返回 -1(如果您按 OK)和 0(如果您按 Cancel)。
MsgBox "您选择的文件是:" & .SelectedItems(1), vbOKOnly + vbInformation, "智能Excel"
End If
End With
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询