Hello,
Thank you in advance for any advice that may be offered!
Am working to assist a colleague with VBA;
Currently, the code works great to create a Word document (report) with an entity's relevant information with respect to data taken from selected cells and tables set up in Excel based upon validation drop-down box (Sheet "Table", column "B2").
The functionality that is lacking that we'd like to add is to have the drop-down box go to the next non-null value in a loop until all of the Word documents get created; for now, we manually advance to the next non-null value.
I have commented out what I have tried in terms of setting up a loop thus far; the loop goes through the drop-down box but does not generate each entities Word document.
Many thanks again,
Karen
'The purpose of the routine is to create a new Word document (report) for each entity
'The performance results and payment are pasted into the Word document and saved with a stamp of the entity name and generation date
'Currently, the drop down box must be manually clicked from sheet "Table" column "B2" to go to the next entity
Sub MPMT_LoopTest1()
Worksheets("table").Activate
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim table1 As Range
Dim HosName As Range
Dim ProjTite As Range
Dim Projdesc As Range
Dim ProjID As Range
Dim address1 As Range
Dim city As Range
Dim zip As Range
'KEW added 7/29/20
'Dim dvCell As Range
'Dim inputRange As Range
'Dim c As Range
'Dim i As Long
Set WordApp = New Word.Application
Set WordDoc = WordApp.Documents.Add(Template:="C:\Users\<pathway>\letter KEW testing v1.docx", NewTemplate:=False, DocumentType:=0)
Set table1 = Range("a10:g15")
Set HosName = Range("b2")
Set address1 = Range("ad5")
Set city = Range("ad6")
Set zip = Range("ad7")
HosName.Select
Selection.Copy
WordApp.Visible = True
WordApp.ActiveDocument.Bookmarks("HosName").Select
Set objSelection = WordApp.Selection
objSelection.PasteSpecial DataType:=wdPasteText
address1.Select
Selection.Copy
WordApp.Visible = True
WordApp.ActiveDocument.Bookmarks("address1").Select
Set objSelection = WordApp.Selection
objSelection.PasteSpecial DataType:=wdPasteText
city.Select
Selection.Copy
WordApp.Visible = True
WordApp.ActiveDocument.Bookmarks("city").Select
Set objSelection = WordApp.Selection
objSelection.PasteSpecial DataType:=wdPasteText
zip.Select
Selection.Copy
WordApp.Visible = True
WordApp.ActiveDocument.Bookmarks("zip").Select
Set objSelection = WordApp.Selection
objSelection.PasteSpecial DataType:=wdPasteText
table1.Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
WordApp.Visible = True
WordApp.ActiveDocument.Bookmarks("table1").Select
Set objSelection = WordApp.Selection
objSelection.Paste
WordApp.ActiveDocument.SaveAs2 Filename:="C:\Users\<pathway>\" & HosName & " " & Format((Year(Now() + 1) Mod 100), "20##") & _
Format((Month(Now() + 1) Mod 100), "0#") & _
Format((Day(Now()) Mod 100), "0#") & "-report.docx"
'KEW added 7/29/20
'Which cell has data validation
'Set dvCell = Worksheets("Table").Range("B2")
'Determine where validation comes from
'Set inputRange = Evaluate(dvCell.Validation.Formula1)
'i = 1
'Begin loop
'Application.ScreenUpdating = False
'For Each c In inputRange
' dvCell = c.Value
' i = i + 1
'Next c
'End loop
'Application.ScreenUpdating = True
End Sub
Display More