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 3 years have passed since last update.

Excel VBA アクティブブック シート名一覧をマクロ実行ブックに転記

Last updated at Posted at 2021-09-23
Option Explicit
Sub main()
  Dim tWB As Workbook
  Dim wdS As Window
  Dim mNL As Collection
  Dim str As Variant
  Dim arrStr as String
  Dim i As Long
    Set mNL = makeAllSheetNameList()
    Set tWB = ThisWorkbook
    Set wdS = tWB.Windows(1)
    i = 1
      'マクロ実行ファイルのシート1に転記
    For Each str In mNL
        if i = 1 then arrStr = str
        if i > 1 then arrStr = arrStr + "," + str
        i = i + 1
      Next
    tWB.Worksheets(1).Range("A" & i) ="array(" & arrStr & ")"
    wdS.WindowState = xlMaximized
    'MsgBox "完了", vbOKOnly, "メッセージ"
End Sub
Function makeAllSheetNameList() As Collection
  'アクティブブックのシート名をコレクションに詰めて返す
  Dim i As Variant
  Dim nameList As Collection
    Set nameList = New Collection
      For Each i In Sheets
          nameList.Add (i.Name)
      Next
    Set makeAllSheetNameList = nameList
End Function
1
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
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?