Consulting

Results 1 to 5 of 5

Thread: Documentum counting?

  1. #1
    VBAX Newbie
    Joined
    Jan 2017
    Posts
    2
    Location

    Documentum counting?

    Hello all!

    So i need a little help for my work. I created a macro that copies my 'project.doc' fully into a new document, but also i would like to add something like that automatically adds a plus number in my 'Number' column whenever a new copy is created. Is there any possibility for this?

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,118
    Location
    Probably, but without a better explanation or example of what you are trying to do then how is anyone's guess.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Jan 2017
    Posts
    2
    Location
    Hey!

    Okay, so

    Sub Macro()


    Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
    Selection.InsertFile FileName:="Project.docx", Range:="", ConfirmConversions _
    :=False, Link:=False, Attachment:=False
    WordBasic.PageSetupMargins Tab:=0, PaperSize:=0, TopMargin:="0.7", _
    BottomMargin:="1", LeftMargin:="1.3", RightMargin:="0.7", Gutter:="0", _
    PageWidth:="21", PageHeight:="29.7", Orientation:=0, FirstPage:=0, _
    OtherPages:=0, VertAlign:=0, ApplyPropsTo:=4, FacingPages:=0, _
    HeaderDistance:="1.25", FooterDistance:="1.25", SectionStart:=2, _
    OddAndEvenPages:=0, DifferentFirstPage:=0, Endnotes:=0, LineNum:=0, _
    CountBy:=0, TwoOnOne:=0, GutterPosition:=0, LayoutMode:=0, DocFontName:= _
    "", FirstPageOnLeft:=0, SectionType:=1, FolioPrint:=0, ReverseFolio:=0, _
    FolioPages:=1
    End Sub

    I use this macro for making my job easier, it's not so clean but this copies my 'project' doc into a new document. What would be nice for me that when everytime i create a new copy document this way, a plus number would be added automatically in my 'Nr: ***x' column, like a counter.

  4. #4
    It would make more sense to save your project document as a macro enabled template containing the part of the following code that logs and applies the number, and create new documents from it, but you can use your existing document as a template.

    We have no idea what your 'Nr: ***x' column is, but open your project document and bookmark the *** bit where the number is to go and name the bookmark bmCount. Save the document and change C:\Path\ in the macro to the location where the document is stored.

    The macro stores the counter in the registry at HKEY_CURRENT_USER\SOFTWARE\VB and VBA Program Settings\MyProject\Counter and increments it each time a new project document is created.

    Option Explicit
    Sub NewProject()
    Dim sCount As String
        sCount = GetSetting("MyProject", "Counter", "Count")
        If sCount = "" Then
            sCount = "1"
        Else
            sCount = val(sCount) + 1
        End If
        Documents.Add Template:="C:\Path\Project.docx"
        'do something with sCount e.g.
        FillBM "bmCount", sCount
        SaveSetting "MyProject", "Counter", "Count", sCount
    lbl_Exit:
        Exit Sub
    End Sub
    
    Private Sub FillBM(strBMName As String, strValue As String)
    'Graham Mayor - http://www.gmayor.com
    Dim oRng As Range
        With ActiveDocument
            On Error GoTo lbl_Exit
            Set oRng = .Bookmarks(strBMName).Range
            oRng.Text = strValue
            oRng.Bookmarks.Add strBMName
        End With
    lbl_Exit:
        Set oRng = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,118
    Location
    As an alternative. You say number column which implies a table. Perhaps something along this line:

    Sub NewProject()
      On Error Resume Next
      ThisDocument.Variables("Counter") = ThisDocument.Variables("Counter") + 1
      If Err.Number <> 0 Then
        ThisDocument.Variables("Counter") = 1
      End If
      On Error GoTo 0
      Documents.Add Template:=ThisDocument.FullName
      ActiveDocument.Tables(1).Cell(2, 4).Range.Text = ThisDocument.Variables("Counter")  '2, 4 assumes row 2, column 4 of the table.
    lbl_Exit:
        Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •