Jump to content

SUBIECTE NOI
« 1 / 5 »
RSS
Info Coronavirus/Vaccinare vs Fake News

Ce telefon sa-mi iau?

Cum circula banii intr-o economie...

ortoped foisor contact-ruptura LIA
 Gingia creste peste masea

Comutatoare si RCCB 18 mm

Filtre apa potabila ptr casa indi...

Despre setarile OBS Studio !
 Cum reacționezi ca tata cand...

Camera auto Zenfox T3 DUO

Identificare Jante

Amintiri din viitor: Blondele, te...
 Smart mobile keeps stopping/ smar...

Culoar de zbor Aeroportul Brasov ...

Intrebare program spion telefon a...

W10 busit
 

Macro Mail Merge

- - - - -
  • Please log in to reply
No replies to this topic

#1
Bratonee

Bratonee

    Junior Member

  • Grup: Members
  • Posts: 152
  • Înscris: 12.02.2012
Salut, incerc sa fac un macro in word care sa imi salveze ca si fisiere individuale in format word documentele pe care le generez folosing mail merge. Datele din mail merge le ia dintr-un excel facut de mine.

In momentul de fata am preluat codul asta gasit pe net:

Option Explicit
Const FOLDER_SAVED As String = "xx"
Const SOURCE_FILE_PATH As String = "xx"
Sub TestRun()
Dim MainDoc As Document, TargetDoc As Document
Dim dbPath As String
Dim recordNumber As Long, totalRecord As Long
Set MainDoc = ActiveDocument
With MainDoc.MailMerge

	 .OpenDataSource Name:=SOURCE_FILE_PATH, SQLStatement:="SELECT * FROM [Sheet1$]"
		
	 totalRecord = .DataSource.RecordCount
	 For recordNumber = 1 To totalRecord
	
		 With .DataSource
			 .ActiveRecord = recordNumber
			 .FirstRecord = recordNumber
			 .LastRecord = recordNumber
		 End With
		
		 .Destination = wdSendToNewDocument
		 .Execute False
		
		 Set TargetDoc = ActiveDocument
		 TargetDoc.SaveAs2 FOLDER_SAVED & xx" & .DataSource.DataFields("xx").Value & " (xx)" & ".docx", wdFormatDocumentDefault
		
		 TargetDoc.Close False
		
		 Set TargetDoc = Nothing
				
	 Next recordNumber
End With
Set MainDoc = Nothing
End Sub


Totul pare sa mearga ok, singura problema pe care o am este ca fisierele initiale au Header/Footer iar dupa ce rulez macro-ul, fisierele noi generate sunt fara Header/Footer.

Aveti idee va rog cum le pot integra si pe acestea ?

Multumesc,

Edited by Bratonee, 03 March 2021 - 16:39.


Anunturi

Bun venit pe Forumul Softpedia!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Forumul Softpedia foloseste "cookies" pentru a imbunatati experienta utilizatorilor Accept
Pentru detalii si optiuni legate de cookies si datele personale, consultati Politica de utilizare cookies si Politica de confidentialitate