SafeConstruct
Gebruiker
- Lid geworden
- 23 apr 2021
- Berichten
- 84
Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
Macro’s kun je op twee manieren opslaan in Word en Excel: binnen een specifiek document, of binnen de applicatie omgeving. Word heeft daar een standaardsjabloon voor: Normal.dotm. Sla je de macro’s daarin op, dan werken de macro’s binnen alle documenten. Voordeel: je hebt je macro’s altijd tot je beschikking, en je documenten bevatten geen macro’s en zijn dus veel makkelijker te distribueren. Nadeel: macro’s die hele specifieke dingen doen werken niet altijd goed in de ‘verkeerde’ documenten.De word-file in bijlage geeft na het kopiëren mijn macro's niet meer weer ... Alle VBA is verdwenen
Sub Prt_pg4()
'
' Prt_pg4 Macro
'
'
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentWithMarkup, Copies:=1, Pages:="4", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
Sub Bouwpartners_aanvullen()
'
' Bouwpartners_aanvullen Macro
'
'
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
Sub VerzendlijstVGP()
Dim Naam As String, Map As String
Map = ZoekMap("C:\Users\Gebruiker\Google Drive\Safe Construct\SC Werven\")
With ActiveDocument.MailMerge
With .DataSource
.FirstRecord = .ActiveRecord
.LastRecord = .ActiveRecord
Naam = .DataFields("VGPINFO").Value & ".docx"
End With
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
ActiveDocument.SaveAs2 FileName:=Map & "\" & Naam, FileFormat:=wdFormatXMLDocument, CompatibilityMode:=15
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
End With
End Sub
Private Function ZoekMap(Optional Startmap As String) As String
'*********************************************************************************
' Early binding: Microsoft Office 11.0 Object Library of later
Dim fDialog As Office.FileDialog
'*********************************************************************************
' Late binding: gebruik objecten
''Dim fDialog As Object
'*********************************************************************************
Dim varFile As Variant
Dim i As Integer
'******************************************************************************
'Opzetten File Dialog met Early Binding.
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
'******************************************************************************
'Opzetten File Dialog met Late Binding.
'Set fDialog = Application.FileDialog(4)
'******************************************************************************
With fDialog
'**************************************************************************
'Pas dit aan voor map met afbeeldingen
.InitialFileName = IIf(Startmap = "", ActiveDocument.Path & "\", Startmap)
'**************************************************************************
.AllowMultiSelect = False
.Title = "Kies een map.."
'**************************************************************************
'Toon het scherm, als methode False teruggeeft is er geen map gekozen.
'**************************************************************************
If .Show = True Then
ZoekMap = .SelectedItems(1)
Else
ZoekMap = "Geen map geselecteerd."
End If
End With
End Function
Sub VerzendlijstPSS()
Dim Naam As String, Map As String
Map = ZoekMap("C:\Users\Gebruiker\Google Drive\Safe Construct\SC Werven\")
With ActiveDocument.MailMerge
With .DataSource
.FirstRecord = .ActiveRecord
.LastRecord = .ActiveRecord
Naam = .DataFields("PSSINFO").Value & ".docx"
End With
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
ActiveDocument.SaveAs2 FileName:=Map & "\" & Naam, FileFormat:=wdFormatXMLDocument, CompatibilityMode:=15
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
End With
End Sub
Sub VerzendlijstVCO()
Dim Naam As String, Map As String
Map = ZoekMap("C:\Users\Gebruiker\Google Drive\Safe Construct\SC Werven\")
With ActiveDocument.MailMerge
With .DataSource
.FirstRecord = .ActiveRecord
.LastRecord = .ActiveRecord
Naam = .DataFields("VCOINFO").Value & ".docx"
End With
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
ActiveDocument.SaveAs2 FileName:=Map & "\" & Naam, FileFormat:=wdFormatXMLDocument, CompatibilityMode:=15
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
End With
End Sub
Sub VerzendlijstPB()
Dim Naam As String, Map As String
Map = ZoekMap("C:\Users\Gebruiker\Google Drive\Safe Construct\SC Werven\")
With ActiveDocument.MailMerge
With .DataSource
.FirstRecord = .ActiveRecord
.LastRecord = .ActiveRecord
Naam = .DataFields("PBINFO").Value & ".docx"
End With
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
ActiveDocument.SaveAs2 FileName:=Map & "\" & Naam, FileFormat:=wdFormatXMLDocument, CompatibilityMode:=15
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
End With
End Sub
Sub Save_doc_pdf()
'
' Save_doc_pdf Macro
'
'
Naam = InputBox("Bestandsnaam? ", "Naam")
ChangeFileOpenDirectory "C:\Users\Gebruiker\Google Drive\DOCS SAVED PDF\"
ActiveDocument.SaveAs2 FileName:=Naam, FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=15
ActiveDocument.ExportAsFixedFormat OutputFileName:=Naam, _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentWithMarkup, Copies:=1, Pages:="4", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
Sub Save_docx_pdf()
'
' Save_docx_pdf Macro
'
'
ActiveDocument.Save
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
Replace(ActiveDocument.FullName, ".docx", ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
ChangeFileOpenDirectory "C:\Users\Gebruiker\Google Drive\Safe Construct\"
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentWithMarkup, Copies:=1, Pages:="4", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
ActiveDocument.Save
End Sub
Sub Ga_naar_pg4()
'
' Ga_naar_pg4 Macro
'
'
.Find.ClearFormatting
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
SelectionWith Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
Sub Pg4()
'
' Pg4 Macro
'
'
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
Selection.Find.ClearFormatting
With Selection.Find
.Text = "4"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
Sub FormatPic300()
''This function will format all images in the document.
''Based on the code from the Tribbs site
Dim iShapeCount As Integer
Dim iILShapeCount As Integer
Dim DocThis As Document
Dim J As Integer
Set DocThis = ActiveDocument
''
Dim origHeight As Integer
Dim origWidth As Integer
Dim scaleHeight As Double
Dim wid As Integer
wid = PixelsToPoints(300) 'reduce the width to 300 pixels
iILShapeCount = DocThis.InlineShapes.Count
If iILShapeCount > 0 Then
For J = 1 To iILShapeCount
origWidth = DocThis.InlineShapes(J).Width
''scaleHeight = wid / origWidth
DocThis.InlineShapes(J).Width = (wid)
DocThis.InlineShapes(J).Height = 170
Next J
End If
End Sub
Sub PicWithCaption()
Dim xFileDialog As FileDialog
Dim xPath, xFile As Variant
On Error Resume Next
Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
If xFileDialog.Show = -1 Then
xPath = xFileDialog.SelectedItems.Item(1)
If xPath <> "" Then
xFile = Dir(xPath & "\*.*")
Do While xFile <> ""
If UCase(Right(xFile, 3)) = "PNG" Or _
UCase(Right(xFile, 3)) = "TIF" Or _
UCase(Right(xFile, 3)) = "JPG" Or _
UCase(Right(xFile, 3)) = "GIF" Or _
UCase(Right(xFile, 3)) = "BMP" Then
With Selection
.InlineShapes.AddPicture xPath & "\" & xFile, False, True
.InsertAfter vbCrLf
.MoveDown wdLine
.Text = xFile & Chr(10)
.MoveDown wdLine
End With
End If
xFile = Dir()
Loop
End If
End If
End Sub
Sub Pictures()
'
' Pictures Macro
'
' = sub Picwithcaption()
Dim xFileDialog As FileDialog
Dim xPath, xFile As Variant
On Error Resume Next
Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
If xFileDialog.Show = -1 Then
xPath = xFileDialog.SelectedItems.Item(1)
If xPath <> "" Then
xFile = Dir(xPath & "\*.*")
Do While xFile <> ""
If UCase(Right(xFile, 3)) = "PNG" Or _
UCase(Right(xFile, 3)) = "TIF" Or _
UCase(Right(xFile, 3)) = "JPG" Or _
UCase(Right(xFile, 3)) = "GIF" Or _
UCase(Right(xFile, 3)) = "BMP" Then
With Selection
.InlineShapes.AddPicture xPath & "\" & xFile, False, True
.InsertAfter vbCrLf
.MoveDown wdLine
.Text = xFile & Chr(10)
.MoveDown wdLine
End With
End If
xFile = Dir()
Loop
End If
End If
' Sub FormatPic300()
Dim iShapeCount As Integer
Dim iILShapeCount As Integer
Dim DocThis As Document
Dim J As Integer
Set DocThis = ActiveDocument
''
Dim origHeight As Integer
Dim origWidth As Integer
Dim scaleHeight As Double
Dim wid As Integer
wid = PixelsToPoints(300) 'reduce the width to 300 pixels
iILShapeCount = DocThis.InlineShapes.Count
If iILShapeCount > 0 Then
For J = 1 To iILShapeCount
origWidth = DocThis.InlineShapes(J).Width
''scaleHeight = wid / origWidth
DocThis.InlineShapes(J).Width = (wid)
DocThis.InlineShapes(J).Height = 170
Next J
End If
End Sub
Sub Verzendlijst_database()
'
' Verzend_test Macro
'
'
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Users\Gebruiker\Google Drive\Safe Construct\SC Projecten.xlsm", _
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=C:\Users\Gebruiker\Google Drive\Safe Construct\SC Projecten.xlsm;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;J" _
, SQLStatement:="SELECT * FROM `DATABASE$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
End Sub
Sub Test_all()
'
' Test_all Macro
'
'
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Users\Gebruiker\Google Drive\Safe Construct\SC Projecten.xlsm", _
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=C:\Users\Gebruiker\Google Drive\Safe Construct\SC Projecten.xlsm;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;J" _
, SQLStatement:="SELECT * FROM `DATABASE$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
End Sub
Sub InsertFileNameOnly()
Dim xPathName As String
Dim xDotPos As Integer
With Application.ActiveDocument
If Len(.Path) = 0 Then .Save
xDotPos = VBA.InStrRev(.Name, ".")
xPathName = VBA.Left(.Name, xDotPos - 1)
End With
Application.Selection.TypeText xPathName
End Sub
Lees eens wat je schrijft: je ‘bewijst’ dat je een module hebt in het document Normal en die wil je kopiëren naar Normal(.dotm)? Het is mij nog nooit gelukt om iets naar zichzelf te kopiëren en dat hóeft natuurlijk ook niet, want het stáát er al!…met het bewijs dat ik onder Normal een Module heb 'NewMacros' waarin wel degelijk een inhoud staat. Deze inhoud wil ik in normal.dotm krijgen maar hoe?
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.