Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 04-05-2019, 06:14 AM
gmaxey gmaxey is offline Generating coversheets using inputboxes Windows 10 Generating coversheets using inputboxes Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Assuming all collected data means 1) Store number, 2) Store Name and 3) Month and year then I don't see why you can't just continue your process and get Month and Year from and inputbox as well.

I would create my template using three content controls. One for store number, one for store name and one for date. I would follows those three CCs with a section breack next page then select the three plus section break and save it as a BuildingBlock e.g., CoverSheet. Then using:


Code:
Sub DatedCoverSheets()
'A basic Word macro coded by Greg Maxey
Dim strName As String, strNum As String, strMY As String
Dim arrParts() As String
Dim oDate As Date
Dim lngIndex As Long
Dim oRng As Range
  strNum = InputBox("What is your store number?")
  strName = InputBox("What is your store name?")
  strMY = InputBox("Enter the month and year e.g., April 2019")
  arrParts = Split(strMY, " ")
  oDate = "1 " & arrParts(0) & " " & arrParts(1)
  For lngIndex = 1 To fcnDaysInMonth(oDate)
    With ActiveDocument.Sections(lngIndex).Range
      .ContentControls(1).Range.Text = "ABC"
      .ContentControls(2).Range.Text = "123"
      'Date the page
      .ContentControls(3).Range.Text = Format(DateAdd("d", lngIndex - 1, oDate), "MMMM dd, yyyy")
    End With
    Set oRng = ActiveDocument.Range
    oRng.Collapse wdCollapseEnd
    ActiveDocument.AttachedTemplate.BuildingBlockEntries("CoverSheet").Insert oRng, True
  Next
  'As a result of the section break in the template and in the building block, there will be two hanging sections at
  'the end of the finished document.  Delete them.
  Set oRng = ActiveDocument.Sections(lngIndex - 1).Range.Paragraphs.Last.Range
  oRng.End = ActiveDocument.Range.End
  oRng.Delete
lbl_Exit:
  Exit Sub
End Sub

Function fcnDaysInMonth(oDateSample As Date)
    fcnDaysInMonth = Day(DateSerial(Year(oDateSample), Month(oDateSample) + 1, 1) - 1)
 End Function
... you get you 28, 29, 30 or 31 pages as required.


Edit: The attached template is a variation of the code above that employs a userform.
Attached Files
File Type: dotm Create Date Cover Sheets.dotm (46.8 KB, 15 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 

Tags
inputbox



Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating coversheets using inputboxes generating a calendar jimmy2016 Mail Merge 2 09-28-2016 11:09 PM
Generating coversheets using inputboxes Generating a Letter Shanna86 Word 9 09-29-2015 09:11 PM
Generating coversheets using inputboxes generating a number in Word John P Word 1 05-31-2012 10:29 PM
Generating Buy/Sell signals accordingly... babapusy Excel 0 04-14-2012 10:11 AM
MS Word 2003 – Generating a ToC krazykasper Word 1 04-29-2009 02:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft