2013-04-04 18 views
1

我一直在努力尋找一種方法來使用VBA一次複印多張紙。問題是我需要他們保持彼此之間的相對參照。例如:一次複印多張紙(保留相關公式)

I have 3 sheets: 
1. Print      (formulas point to TV - Input) 
2. Print - Input 
3. Print - plan    (formulas point to TV - Input) 

I need to copy them so that all formulas point to their new respective sheets. 

1. Print (2)     (formulas point to Print - Input (2)) 
2. Print - Input (2) 
3. Print - plan (2)   (formulas point to Print - Input (2)) 

這可以通過Ctrl輕鬆完成。 +將圖紙拖動到新的位置。但是,如何在VBA中做到這一點?

編輯: 名稱「打印」設置爲運行時。所以它也可以是電視或收音機。它是從一個字符串中調出來的。

任何幫助表示讚賞!

回答

2

嘗試是這樣的:

Sheets(Array("Print", "Print - input", "Print - plan")).Copy After:=Sheets(Sheets.Count) 

Edited-與索引引用

Sheets(Array(1, 2, 3)).Copy After:=Sheets(Sheets.Count) 

隨着變量引用:

Dim sht1 as String, sht2 as String, sht3 As String 
sht1 = "Print" 
sht2 = "Print - input" 
sht3 = "Print - plan" 
Sheets(Array(sht1, sht2, sht3)).Copy After:=Sheets(Sheets.Count) 

使用動態陣列(這裏3元件靜態的,但也可以是任何動態的):

Dim arrSHT as Variant 
arrSHT = array("Print", "Print - input", "Print - Plan") 
Sheets(arrSHT).Copy After:=Sheets(Sheets.Count) 
+0

謝謝,這個作品!然而,這是更大功能的一部分,並且表格名稱是動態設置的。有沒有辦法傳入動態數組變量或其他東西? – 2013-04-04 11:43:46

+0

我添加了一些額外的選項,我的答案... – 2013-04-04 11:49:42

+0

謝謝!選項3正是我所需要的:) – 2013-04-04 11:58:41

相關問題