2017-05-26 7 views
-1

ブックには、Main.xlsxと言うと、複数のシートがあります。Main418, Main418_NotBilled, Main923, Main923_NotBilledです。あるブックから別のブックにデータをコピーする

私は2つのワークブックがWokbook_418.xlsxWokbook_923.xlsxと言う別の場所にあります。 Wokbook_418.xlsxには、3つのシートTotal, Sheet418, Sheet418_NotBilledがあります。同様にWokbook_923.xlsxには3枚のシートTotal, Sheet923, Sheet923_NotBilledがあります。

私の要件は、Wokbook_418_copy_26May.xlsx and Wokbook_923_copy_26May.xlsx respectivelyという別の場所に2つのワークブック"Wokbook_418.xlsx" and "Wokbook_923.xlsx"をコピーする必要があるmacro in Main.xlsxです。

Wokbook_418_copy_26May.xlsx」には、 - 合計シートには触れたくありません。 - シート「Sheet418」のデータをシート「Main418」のデータに置き換えます。 (シート「Main418」はMain.xlsxで利用可能) - シート「Sheet418_NotBilled」のデータをシート「Main418_NotBilled」のデータに置き換えます。 (シート「Main418_NotBilled」はMain.xlsxで利用可能)

Wokbook_923_copy_26May.xlsx」の - 合計シートには触れたくありません。 - シート「」のデータをシート「Main923」のデータで置き換えます。 (シート「Main923」はMain.xlsxで利用可能) - シート「Sheet923_NotBilled」のデータをシート「Main923_NotBilled」のデータに置き換えたいとします。 (シート "Main923_NotBilled"はMain.xlsxで利用可能です)

私はこのレベルの専門知識をExcelで持っていません。

この機能を実現するには、(正確なコードではなく)いくつかのガイダンスが必要です。

これでお手伝いしてください。

答えて

0

Main.xlsxブック内のマクロから、各ブックを開き、シートの情報をMain.xlsx内にコピーし、編集したブックを名前付け基準で新しい場所に保存することができます。例:

Sub Macro1() 

'opens the Workbook_418.xlsx file 
Workbooks.Open Filename:="your_file_path_here\Workbook_418.xlsx" 

'Activates your Main.xlsx workbook 
Windows("Main.xlsx").Activate 

'Selects your Main418 worksheet and copies the entire sheet 
    Sheets("Main418").Select 
    Cells.Select 
    Selection.Copy 

'Activates your Workbook_418.xlsx workbook 
Windows("Workbook_418.xlsx").Activate 

'Selects your Sheet418 worksheet and pastes the entire sheet 
    Sheets("Sheet418").Select 
    Cells.Select 
    ActiveSheet.Paste 

'Saves the Workbook_418.xlsx file with your new file name 
    'formats a string to return the day & month 
    Dim x As String 
x = Day(Date) & MonthName(Month(Date)) 

Application.ActiveWorkbook.SaveAs Filename:="your_file_path_here\Workbook_418_" & x & ".xlsx", _ 
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False 

End Sub 
+0

ありがとうございました。ありがとうございました。私は1つのシートで操作を実行することができます。すべてのシートの内容を読み込んで保存するようにマクロを更新します。ありがとうございました。 – Mani

0

上記の応答で@Daveが提供するガイダンスを使用して、すべてのシートに対して作成しました。

Sub Macro1() 


    Dim LCounter As Integer 

    For LCounter = 1 To 4 

     'BUNumber should be 417, 618, 641, 682 
      If LCounter = 1 Then 
       BUNumber = 417 
      ElseIf LCounter = 2 Then 
       BUNumber = 618 
      ElseIf LCounter = 3 Then 
       BUNumber = 641 
      ElseIf LCounter = 4 Then 
       BUNumber = 682 
      End If 

     ''''''''''''''''''''''''''''''''''''' File Operation Start''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
     'opens the Reference_BU417.xlsx file 
     Workbooks.Open Filename:="C:\Users\makumar\Desktop\file for mani\reference_files\Reference_BU" & BUNumber & ".xlsx" 

     'Activates your Main sheet.xlsm workbook 
     Windows("Main sheet.xlsm").Activate 

      'Selects your 417 worksheet and copies the entire sheet 
       Sheets("" & BUNumber & "").Select 
       Cells.Select 
       Selection.Copy 

     'Activates your Reference_BU417.xlsx workbook 
     Windows("Reference_BU" & BUNumber & ".xlsx").Activate 

      'Selects your BU417 worksheet and pastes the entire sheet 
       Sheets("BU" & BUNumber & "").Select 
       Cells.Select 
       ActiveSheet.Paste 




     'Activates your Main sheet.xlsm workbook 
     Windows("Main sheet.xlsm").Activate 

      'Selects your 417_NotBilled worksheet and copies the entire sheet 
       Sheets("" & BUNumber & "_NotBilled").Select 
       Cells.Select 
       Selection.Copy 

     'Activates your Reference_BU417.xlsx workbook 
     Windows("Reference_BU" & BUNumber & ".xlsx").Activate 

      'Selects your BU417_NotBilled worksheet and pastes the entire sheet 
       Sheets("BU" & BUNumber & "_NotBilled").Select 
       Cells.Select 
       ActiveSheet.Paste 




     'Saves the Reference_BU417.xlsx file with your new file name 
      With ActiveWorkbook 
       .SaveCopyAs "C:\Users\makumar\Desktop\file for mani\generated_files\" & _ 
          Left(.Name, InStrRev(.Name, ".") - 1) & _ 
          "_" & Format(Date, "ddmmmyyyy") & ".xlsx" 
      End With 


     'closes the Reference_BU417.xlsx file 
     Workbooks("Reference_BU" & BUNumber & ".xlsx").Close SaveChanges:=False 

     '''''''''''''''''''''''''''''''''''''File Operation End''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 


     MsgBox ("Complete for: " & BUNumber & "") 

    Next LCounter 


End Sub 
関連する問題