1
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.

VBA 改行をOSによって切り替える

Last updated at Posted at 2019-12-20

Excel For MacでVBAいじってて、
改行をOSで切り替えたいなと思ったら、案外簡単だった。
MacだとActiveXが使えなかったりしていろいろ不便ですね・・

Private Function LinefeedCode() As String
    If Application.OperatingSystem Like "*Mac*" Then
      ' Mac 向け
      LinefeedCode = vbCr
    Else
      ' Windows 向け
      LinefeedCode = vbCrLf
    End If
End Function

追記:
@nukie_53さんがもっと簡単な方法を教えてくださいました。
ありがとうございます!

vbNewLineというのが、使えるそうです!
※以下、コメントでご紹介頂いたものを貼らせて頂きました

その他の定数 | Microsoft Docs

定数 説明
vbNewLine Chr(13) + Chr(10)。Macintosh の場合は、Chr(13) プラットフォーム固有の改行文字。現在のプラットフォームに対応する文字が使用されます。
1
0
1

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
1
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?