+ Reply to Thread
Results 1 to 4 of 4

Configuring code to pull data from .docm user forms

Hybrid View

  1. #1
    Registered User
    Join Date
    09-28-2015
    Location
    400
    MS-Off Ver
    2010
    Posts
    4

    Configuring code to pull data from .docm user forms

    Hi I can use the following code successfully to pull userform data from .docx files to Excel but unfortunately I need it to pull from .docm files. I have tried changing the

    strFile = Dir(strFolder & "\*.docx", vbNormal)
    to

    strFile = Dir(strFolder & "\*.docm", vbNormal)
    to no avail. Any help would be most appreciated.

    Sub GetFormData2()
         'Note: this code requires a reference to the Word object model
        Application.ScreenUpdating = False
        Dim wdApp As New Word.Application
        Dim wdDoc As Word.Document
        Dim CCtrl As Word.ContentControl
        Dim strFolder As String, strFile As String
        Dim WkSht As Worksheet, i As Long, j As Long
        strFolder = GetFolder
        If strFolder = "" Then Exit Sub
        Set WkSht = ActiveSheet
        i = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row
        strFile = Dir(strFolder & "\*.docx", vbNormal)
        While strFile <> ""
            i = i + 1
            Set wdDoc = wdApp.Documents.Open(Filename:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
            With wdDoc
                j = 0
                For Each CCtrl In .ContentControls
                    j = j + 1
                    WkSht.Cells(i, j) = CCtrl.Range.Text
                Next
            End With
            wdDoc.Close SaveChanges:=False
            strFile = Dir()
        Wend
        wdApp.Quit
        Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing
        Application.ScreenUpdating = True
    End Sub
     
    Function GetFolder() As String
        Dim oFolder As Object
        GetFolder = ""
        Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
        If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
        Set oFolder = Nothing
    End Function

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Configuring code to pull data from .docm user forms

    How is it not working when you change from docx to docm?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-28-2015
    Location
    400
    MS-Off Ver
    2010
    Posts
    4

    Re: Configuring code to pull data from .docm user forms

    It doesn't give an error message - just does absolutely nothing and doesn't pull anything across.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Configuring code to pull data from .docm user forms

    Have you stepped through the code with F8 to see what's happening, specifically to see if any files are actually being picked up?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Access code pull data in forms.fields from sql request troubleshot
    By saf111 in forum Access Tables & Databases
    Replies: 1
    Last Post: 12-20-2013, 06:02 AM
  2. [SOLVED] Global code to center user forms
    By KevBotes in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2013, 07:33 AM
  3. Code for multiple User Forms
    By Guido Meng in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-06-2013, 08:06 PM
  4. [SOLVED] User forms - choosing location of your data to be shown in your user form
    By jasonbwt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2012, 08:48 AM
  5. Cannot pull web data when User is using IE8. Same code works with IE7 and below
    By Nebula1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-08-2012, 01:44 PM
  6. user forms code, etc
    By jhi3600 in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 08-10-2011, 02:28 AM
  7. Macro Code for User Forms
    By heidilu in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-12-2010, 06:24 AM
  8. VBA Code and User Forms.
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2010, 01:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1