0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Excel VBA エラー465「リモートサーバがないか、使用できる状況ではありません」の解決法

Posted at

事の発端

Excel からWordにグラフを複数回貼り付けるマクロを作っていたら、エラー番号465の「リモートサーバがないか、使用できる状況ではありません」というようなエラーが出るようになりました。

症状

面白いことに、マクロを実行したら2回に一回エラーが必ず出る。
なので多分、どこかでオブジェクトへの参照を解除(Set オブジェクト変数 = Nothing)を忘れているとかで出ているエラーだと思われました。しかし、原因の箇所がどうしても判明しない。

そこで、強引な解決方法を見つけたので紹介します。

解決方法

Endを使います。

End Subじゃないです。Endです。
つまり・・・

Sub main()

   (・・・色んな処理・・・)

   End  ← ココ重要!!
End Sub

ということです。
これで「リモートサーバがないか、使用できる状況ではありません」というエラーがでなくなります。原因が見つからないときの一時的な応急処置としてですが。
なぜ、コレで解決するのか、自分の場合偶然でしたが、理由としては以下の通りだと思います。

End sub と Endの違い

Exit Sub、はsubから抜けるだけです。このsubを呼び出したprocedureに戻ります。プログラムが終了するわけではありません。
endはプログラムを終了させます。

引用元:https://okwave.jp/qa/q4093153.html
なるほど。なるほど。

VBAの関連記事

Excel VBA PasteSpecial で出るエラーの回避方法
VBAで相対パスから絶対パスに変換する関数

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?