Question : Insert Script into Excel Workbooks as module1

Hi Experts,

I've few excel workbooks were required script as Modual1. Is there any possibilities for me to insert this script  in workbooks without go through normal process (alt F11, insert module and paste the script).

Let say I've 15 workbooks were required same script as module1, what I would like to have is to select all these workbooks and insert the scripts in single process, similar to batch update.

The workbooks are saved in same folder.

I've attached the script that I need to insert in the workbooks.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
Sub Copy_Paste()

    Dim WB As Workbook
    Dim objFileDLG As Office.FileDialog
    Dim strFilePath, lnLoop, lnLineNo, lcTargetCell
    
    Set objFileDLG = Application.FileDialog(msoFileDialogFilePicker)
    lnLoop = 1
    lnLineNo = 2
    
    Do While lnLoop < 4
        With objFileDLG
            .Filters.Add "Excel Files", "*.xls", 1
            .FilterIndex = 1
            .AllowMultiSelect = False
            .Title = "Select The Workbook to copy From "
            If .Show() <> 0 Then
                strFilePath = .SelectedItems(1)
            End If
        End With
        
        Set WB = Workbooks.Open(strFilePath)
        WB.Activate
        WB.Worksheets(1).Range("A3:H7").Copy
        Select Case lnLoop
            Case 1
                lcTargetCell = "B2"
            Case 2
                lcTargetCell = "B7"
            Case 3
                lcTargetCell = "B12"
            Case 4
                lcTargetCell = "B16"
            Case 5
                lcTargetCell = "B22"
            Case 6
                lcTargetCell = "B22"
            Case 7
                lcTargetCell = "B27"
            Case 8
                lcTargetCell = "B32"
     
        End Select
        
        ThisWorkbook.Worksheets(1).Activate
        Range(lcTargetCell).Activate
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
                   xlNone, SkipBlanks:=False, Transpose:=False
        Application.CutCopyMode = False
        lnLoop = lnLoop + 1
        WB.Close
        Set WB = Nothing
        
    Loop
End Sub

Answer : Insert Script into Excel Workbooks as module1

Oh...one more thing you need to do.  In the workbook you download, add a reference to:

Microsoft visual basic for applications extensibility 5.3

while in the VBE, go to tools>>references and find it in there and check it...

:-)
ALbert
Random Solutions  
 
programming4us programming4us