[英]Copy Paste Worksheets names to another workbook
我很難做到這一點。 當我啟動宏時,它不會產生任何錯誤,但是也不會拋出任何結果。
Sub EmpresasCubiertas()
Dim x As Workbook
Dim y As Workbook
'## Open both workbooks first:
Set x = Workbooks.Open("G:\Estudios\Biblioteca\Mercado Accionario Chileno\InsertarEmpresa.xlsm")
Set y = Workbooks.Open("G:\Estudios\Biblioteca\Mercado Accionario Chileno\Procesamiento.xlsm")
For i = 3 To x.Sheets.Count
'Now, paste to y worksheet:
y.Sheets(1).Range(“A” & i) = x.Sheets(i).Name
Next i
End Sub
請注意,工作簿“ y”是我首先打開以運行宏的工作簿。 即它已經打開,如果有幫助的話。
問題在於循環中缺少Range旁邊的Value屬性。 它應該顯示為
y.Sheets(1).Range(“A” & i).Value = x.Sheets(i).Name
我假設您故意選擇從i = 3開始復制工作表名稱。如果需要所有工作表,只需將i的值更改為1。
嘗試這個:
Sub CopyWorkBookNames()
Application.ScreenUpdating = False 'To avoid screen flickering
Dim y As Workbook
Dim x As Workbook
Set y = Application.ActiveWorkbook
Set x = Application.Workbooks.Open("FilePathToCopyFrom.xlsx")
'Copy and paste worksheet names, in the workbook running the code, starting from cell A3.
'If You want to paste into cell A1, decrement i in the range below accordingly
For i = 3 To x.Sheets.Count
y.ActiveSheet.Range("A" & i).Value = x.Sheets(i).Name
Next i
x.Close 'Add SaveChanges Options as needed
Application.ScreenUpdating = True
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.