Jump to content

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

XP NTLDR is missing

NVIDIA RTX 4090 vs RTX 3090 Ti | ...

I5 10400F sau I5 11400F?
 Google Pixel 6 vs Samsung S21 Fe

Abatere de la autorizatie casa

Rețeaua RCS va pune Aleph si toat...

Navigatie blocata
 Recomandare tastatura

Slavia Praga - CFR Cluj 6.10.2022...

Problema citire stick USB

Recuperare document Office
 USB-C obligatoriu pe toate dispoz...

Thessaloniki - Izmir Ferry incep...

Informații despre VOYO !

VUNK - Felicitari, ai reusit!
 

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