Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2017, 07:13 AM
gmaxey gmaxey is offline Pizza Tips - Simple Addition In Word Document Windows 7 32bit Pizza Tips - Simple Addition In Word Document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

SR/SC

Advancing your solutions a bit, you could use content controls to input the daily addition or deduction and then leverage their exit events to calculate. I've attached a file to go along with this code. Note - The code goes in the ThisDocument module of the project.

Code:
Option Explicit
Dim oTblInput As Table, oTblRecord As Table
Private Sub Document_ContentControlOnExit(ByVal oCC As ContentControl, Cancel As Boolean)
  Select Case oCC.Title
    Case "Add"
      If IsNumeric(oCC.Range.Text) Then
        oCC.Range.Text = FormatCurrency(oCC.Range.Text, 2, True)
        oTblInput.Cell(1, 4).Range.Text = FormatCurrency(CDbl(oCC.Range.Text) + CDbl(fcnCellText(oTblInput.Cell(1, 4))), 2, True)
        With oTblRecord
          .Rows.Add oTblRecord.Rows(3)
          .Cell(3, 1).Range.Text = Format(Date, "MMMM dd, yyyy")
          .Cell(3, 2).Range.Text = oCC.Range.Text
          'After first run you can delete the blank row at the bottom of the record table.
        End With
      End If
    Case "Subtract"
      If IsNumeric(oCC.Range.Text) Then
        oCC.Range.Text = FormatCurrency(oCC.Range.Text, 2, True)
        oTblInput.Cell(2, 4).Range.Text = FormatCurrency(CDbl(fcnCellText(oTblInput.Cell(2, 4)) - CDbl(oCC.Range.Text)), 2, True)
      End If
    Case Else
 
  End Select
  ActiveDocument.Fields.Update
lbl_Exit:
  Exit Sub
End Sub
Private Sub Document_Open()
  Set oTblInput = ActiveDocument.Tables(1)
  Set oTblRecord = ActiveDocument.Tables(2)
  ActiveDocument.SelectContentControlsByTitle("Add").Item(1).Range.Text = vbNullString
  ActiveDocument.SelectContentControlsByTitle("Subtract").Item(1).Range.Text = vbNullString
lbl_Exit:
  Exit Sub
End Sub
Function fcnCellText(oCell As Cell) As String
  fcnCellText = Left(oCell.Range.Text, Len(oCell.Range.Text) - 2)
  If fcnCellText = vbNullString Then fcnCellText = "0"
lbl_Exit:
  Exit Function
End Function

Attached Files
File Type: docm Add.docm (37.1 KB, 12 views)
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pizza Tips - Simple Addition In Word Document Addition James__S Word 1 08-18-2016 06:20 PM
Pizza Tips - Simple Addition In Word Document Addition of new colors marif300 Project 3 05-20-2016 07:32 AM
Pizza Tips - Simple Addition In Word Document Addition Formula is Giving a Date!!! MikeM3 Excel 9 01-15-2016 02:41 AM
Pizza Tips - Simple Addition In Word Document Need tips for creating a specific word format DomDom Word 5 09-24-2014 01:24 AM
Pizza Tips - Simple Addition In Word Document Putting a horizontal line in a Word Document -- should be simple, right? biotechguy Word 4 05-10-2010 11:58 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:23 AM.


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