Seba Robles
Board Regular
- Joined
- May 16, 2018
- Messages
- 73
- Office Version
- 2019
- 2016
- Platform
- Windows
I have the following code with which I want to loop through all the data validation options available in the drop down list and copy/paste that output of the data validation option into MS Word.
The code "works"... However, when it pastes the report into MS Word, it pastes the last list option selected by the user instead of looping through the list and changing the report responses.
Say, the data validation has "Option1" and "Option2".. For each of the Options there is a template/report that has different values depending on the data validation selection. When I run the code, it will copy and paste the report for Option1 or Option2 (regarding on which was last selected by the user) TWICE (because there are only two options in the dropdown)....
Any idea how I could fix this?
The code "works"... However, when it pastes the report into MS Word, it pastes the last list option selected by the user instead of looping through the list and changing the report responses.
Say, the data validation has "Option1" and "Option2".. For each of the Options there is a template/report that has different values depending on the data validation selection. When I run the code, it will copy and paste the report for Option1 or Option2 (regarding on which was last selected by the user) TWICE (because there are only two options in the dropdown)....
Any idea how I could fix this?
Code:
Sub GenerateReports()
Dim dvCell, inputRange, c As Range
Dim i As Long
Dim objWord, objDoc As Object
Set dvCell = Worksheets("Reports").Range("D3")
Set inputRange = Evaluate(dvCell.Validation.Formula1) 'My data validation is not a formula but a dynamic range instead
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
i = 1
For Each c In inputRange
dvCell = c.Value
ActiveWindow.View = xlNormalView
Range("A9:G48").Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
objWord.Visible = True
objWord.Selection.Paste
objWord.Selection.TypeParagraph
i = I + 1
Next c
End Sub