Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-15-2018, 05:55 AM
Broman66 Broman66 is offline Open directory in word using macro Windows 7 64bit Open directory in word using macro Office 2013
Novice
Open directory in word using macro
 
Join Date: Mar 2018
Posts: 1
Broman66 is on a distinguished road
Default Open directory in word using macro

Hi.
I want to change this macro.

Sub Makro1()
'
' Makro1 Makro
'
'
ActiveDocument.MailMerge.OpenDataSource Name:= _


"Q:\SESTORIN\opt\NIMAB Produktion\Div Nimab projektering\TEST PROJEKTSTRUKTUR\25. Övrigt\03. Databas\Projektregister.xlsx" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=Q:\SESTORIN\opt\NIMAB Produktion\Div Nimab projektering\TEST PROJEKTSTRUKTUR\25. Övrigt\03. Databas\Projektregister.xlsx;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database=" _
, SQLStatement:="SELECT * FROM `Blad1$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
End Sub

What I want to change is

Q:\SESTORIN\opt\NIMAB Produktion\Div Nimab projektering\TEST PROJEKTSTRUKTUR\25. Övrigt\03. Databas\Projektregister.xlsx

I would like to open the directory so I can choose the specific file I want to use instead of
"Q:\SESTORIN\opt\NIMAB Produktion\Div Nimab projektering\TEST PROJEKTSTRUKTUR\25. Övrigt\03. Databas\Projektregister.xlsx" _

And after I have choosen the file I want to use the macro will continue.
Anyone who can help me?
Reply With Quote
  #2  
Old 03-15-2018, 02:40 PM
macropod's Avatar
macropod macropod is offline Open directory in word using macro Windows 7 64bit Open directory in word using macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try something based on:
Code:
Sub Demo()
Dim strWkBkNm As String
With Application
  .DisplayAlerts = wdAlertsNone
  'Select a data source
  With .FileDialog(FileDialogType:=msoFileDialogFilePicker)
    .AllowMultiSelect = False
    .Filters.Add "Excel Files", "*.xls*", 1
    If .Show = True Then
      strWkBkNm = .SelectedItems(1)
    Else
      Exit Sub
    End If
  End With
  With .ActiveDocument
    With .MailMerge
      'Disconnect from the data source
      .MainDocumentType = wdNotAMergeDocument
      'Define the mailmerge type
      .MainDocumentType = wdFormLetters
      'Suppress Blank Lines
      .SuppressBlankLines = True
      'Define the output
      .Destination = wdSendToNewDocument
      'Connect to the data source, Applying the required SQL Statement,
      'including filters, on the 'SQLStatement' line and the
      ''SQLStatement1' line, for SQL Statements over 255 characters
      .OpenDataSource Name:=strWkBkNm, ReadOnly:=True, _
          AddToRecentFiles:=False, LinkToSource:=False, _
          Connection:="Provider=Microsoft.ACE.OLEDB.12.0;" & _
          "User ID=Admin;Data Source=StrWkBkNm;" & _
          "Mode=Read;Extended Properties=""HDR=YES;IMEX=1"";", _
          SQLStatement:="SELECT * FROM `Blad1$`", _
          SQLStatement1:="", SubType:=wdMergeSubTypeAccess
      With .DataSource
        .FirstRecord = wdDefaultFirstRecord
        .LastRecord = wdDefaultLastRecord
      End With
      .Execute Pause:=False
      'Disconnect from the data source
      .MainDocumentType = wdNotAMergeDocument
    End With
  End With
  .DisplayAlerts = wdAlertsAll
End With
End Sub
PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the latest filename from directory with a macro spider85 Word VBA 2 07-10-2017 10:43 PM
Open directory in word using macro Mailmerge Directory - TableJoiner Macro Gwinnett Mail Merge 3 03-01-2017 09:25 AM
Open directory in word using macro directory: want to a ensure all three lines in a directory entry appear on the same page. JON25T Mail Merge 3 12-22-2016 01:34 PM
Open directory in word using macro Word 2010 Macro to rename Folder in Directory staicumihai Word VBA 2 10-28-2016 03:01 AM
Open directory in word using macro How To Apply A VBA Macro to All Subfolders in a Directory of a docx. Extension jc491 Word VBA 8 09-11-2015 08:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:31 PM.


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