Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 05-25-2019, 12:33 PM
JennEx JennEx is offline Unexpected Big Problem With Mail Merge via Excel VBA - DataLink Problem Windows XP Unexpected Big Problem With Mail Merge via Excel VBA - DataLink Problem Office 2013
Competent Performer
Unexpected Big Problem With Mail Merge via Excel VBA - DataLink Problem
 
Join Date: May 2010
Posts: 162
JennEx is on a distinguished road
Default Stumped.

This is driving me insane.


Code:
    StrSQL = "SELECT * FROM [DATA$] WHERE [TYPE]='" & itype & "' AND [SIG_CREW]='" & isubresp & "' " & _
        "ORDER BY [STARTS] ASC, [COMPLEX] ASC, [UNIT] ASC"
 
    Set objWord = CreateObject("Word.Application")
    With objWord
        .DisplayAlerts = False
        .Visible = True
        Set oDoc = .Documents.Open(Filename:=fName, ConfirmConversions:=False, _
            ReadOnly:=True, AddToRecentFiles:=False, Visible:=True)
        With oDoc
            With .MailMerge
                .MainDocumentType = wdFormLetters
                .Destination = wdSendtToNewDocument
                .SuppressBlankLines = True
                .OpenDataSource Name:=StrSrc, AddToRecentFiles:=False, LinkToSource:=False, ConfirmConversions:=False, _
                    ReadOnly:=True, format:=wdOpenFormatAuto, Connection:="Provider=Microsoft.ACE.OLEDB.12.0;" & _
                    "User ID=Admin;Data Source=" & StrSrc & ";Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";", _
                    SQLStatement:=StrSQL, SQLStatement1:="", SubType:=wdMergeSubTypeAccess
                .Execute Pause:=False
            End With
            .Close False
        End With
        .DisplayAlerts = True
        
        'page break routine only for sports reports
        If (Left(itype, 1) <> "G") And (itype <> "DT") Then   'exclude GS reports
            With .activedocument
                If .Sections.count > 1 Then
                    For Each HdFt In .Sections(.Sections.count).Headers
                        If HdFt.Exists Then
                            HdFt.Range.FormattedText = .Sections(1).Headers(HdFt.index).Range.FormattedText
                            HdFt.Range.Characters.Last.Delete
                        End If
                    Next
                    For Each HdFt In .Sections(.Sections.count).Footers
                        If HdFt.Exists Then
                            HdFt.Range.FormattedText = .Sections(1).Footers(HdFt.index).Range.FormattedText
                            HdFt.Range.Characters.Last.Delete
                        End If
                    Next
                End If
                Do While .Sections.count > 1
                    .Sections(1).Range.Characters.Last.Delete
                    DoEvents
                Loop
                .Range.Characters.Last.Delete
            End With
        End If
    
    End With
    
    Set oDoc2 = objWord.activedocument

    'save newly created document
    With oDoc2
        myPath = "u:\PWS\Parks\Parks Operations\Sports\Sports17\WORKORDERS\" & format(ws_vh.Range("B17"), "ddd dd-mmm-yy")
        .SaveAs myPath & "\" & rpt_od & ".docx"
        If dest = 2 Then
            .PrintOut
        End If
        '.Close
    End With
        

    Set oDoc = Nothing: Set oDoc2 = Nothing ': Set objWord = Nothing

Above is the code that is saving the merged documents.


I have no problem creating or working with these reports at home. They create, save, can be opened, editted and resaved without any errors. The only think that sticks out as being unusual is "[Compatibility Mode]"


If I take these same files on my thumbdrive to work, I can access the files but any edits cannot be saved. I am unable to open the documents from within my application, a feature of my excel application I have no issues with at home.
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel to word Mail Merge problem mark_kofi Mail Merge 4 07-17-2018 03:49 PM
Unexpected Big Problem With Mail Merge via Excel VBA - DataLink Problem Mail Merge View problem drgt Mail Merge 2 02-14-2017 04:31 AM
Unexpected Big Problem With Mail Merge via Excel VBA - DataLink Problem Mail Merge Problem Hook Mail Merge 2 01-11-2012 09:36 AM
Mail Merge Problem JohnRG Mail Merge 0 11-02-2009 02:50 AM
problem in Mail merge rjagathe Mail Merge 0 08-12-2009 08:25 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:57 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