热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用Dim时无效的外部程序

如何解决《使用Dim时无效的外部程序》经验,为你挑选了1个好方法。

我用以下代码得到"无效的外部程序"错误.请问有人请告诉我这里哪里出错了.

Dim Asset As String, AssetURL As String

Asset = Range("B1").Value

If Asset = "1" Then
    AssetURL = "X:\Docs\excel0001.xls"
Elseif Asset = "2" Then
    AssetURL = "X:\Docs\excel0002.xls"
End If

Range("C1").Value = AssetURL

Gary's Stude.. 5

确保您可以在多个Subs中运行代码的最佳方法是使其成为Public Sub:

Public Sub qwerty()
    Dim Asset As String, AssetURL As String

    Asset = Range("B1").Value

    If Asset = "1" Then
        AssetURL = "X:\Docs\excel0001.xls"
    ElseIf Asset = "2" Then
        AssetURL = "X:\Docs\excel0002.xls"
    End If

    Range("C1").Value = AssetURL
End Sub

如果要在其他地方执行此代码,则应使用:

Sub OtherSub()
    'OtherSub Code
    Call qwerty() 'or just qwerty
    'Rest of OtherSub Code
End Sub

相关问题上使用Call,以利用Sub内的另一Sub



1> Gary's Stude..:

确保您可以在多个Subs中运行代码的最佳方法是使其成为Public Sub:

Public Sub qwerty()
    Dim Asset As String, AssetURL As String

    Asset = Range("B1").Value

    If Asset = "1" Then
        AssetURL = "X:\Docs\excel0001.xls"
    ElseIf Asset = "2" Then
        AssetURL = "X:\Docs\excel0002.xls"
    End If

    Range("C1").Value = AssetURL
End Sub

如果要在其他地方执行此代码,则应使用:

Sub OtherSub()
    'OtherSub Code
    Call qwerty() 'or just qwerty
    'Rest of OtherSub Code
End Sub

相关问题上使用Call,以利用Sub内的另一Sub


推荐阅读
author-avatar
真实的姜伯约_832
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有