Hi,
I'm trying to cycle through the sheets in a workbook. In each cycle, I run some copy paste code onto a template and save that template with a name from a specific cell in the cycling workbook's active sheet. The problem is that while the saving code cycles and saves file names correctly, my ws.Application.Run ("CopyDTDvalues") does not cycle to copy paste correctly. It copy pastes the 1st sheet's values over and over. Can I have some advice on how to make sure the copy/paste code also cycles through the worksheets? Thanks!
Here is the code for my overarching code that cycles and calls another macro:
Here is some sample code from my copy/paste code.
I'm trying to cycle through the sheets in a workbook. In each cycle, I run some copy paste code onto a template and save that template with a name from a specific cell in the cycling workbook's active sheet. The problem is that while the saving code cycles and saves file names correctly, my ws.Application.Run ("CopyDTDvalues") does not cycle to copy paste correctly. It copy pastes the 1st sheet's values over and over. Can I have some advice on how to make sure the copy/paste code also cycles through the worksheets? Thanks!
Here is the code for my overarching code that cycles and calls another macro:
Code:
Sub Transfer_All_DTD_Inputs()
Dim ws As Worksheet
Dim ThisFile
Dim NameToBeSaved
For Each ws In ActiveWorkbook.Worksheets
ws.Application.Run ("CopyDTDvalues")
ThisFile = ws.Range("A2").Value
NameToBeSaved = ThisFile & "_dtd"
ActiveWorkbook.SaveAs Filename:=NameToBeSaved
Workbooks(NameToBeSaved & ".xls").Close SaveChanges:=False
Workbooks("DTD Bloomberg API template_v4.xlsm").Activate
On Error Resume Next 'Will continue if an error results
Next ws
End Sub
Here is some sample code from my copy/paste code.
Code:
Sub CopyDTDvalues()
Application.Workbooks.Open ("C:\...blanktemplate_dtd.xls")
Windows("DTD Bloomberg API template_v4.xlsm").Activate
Range("B5:C5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("blanktemplate_dtd.xls").Activate
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub