Word To Excel Pack
Word To Excel Pack
Sub Rectangle2_Click()
'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Substituting excel to word bookmark
Dim objX As Object
Dim rng1 As Range
Dim rng2 As Range
Dim wb As Workbook
Dim wsControl As Worksheet
Dim wsData As Worksheet
'
Dim oApp As Word.Application
Dim oBookMark As Word.Bookmark
Dim oDoc As Word.Document
'
Dim strDocumentFolder As String
Dim strTemplate As String
Dim strTemplateFolder As String
Dim strDocumentAddress As String
Dim lngTemplateNameColumn As Long
Dim strWordDocumentName As String
Dim lngDocumentNameColumn As Long
Dim lngRecordKount As Long ' not used but retained for future use
Set wb = ThisWorkbook
Set wsControl = wb.Worksheets("Control Sheet")
wsControl.Activate
lngTemplateNameColumn = wsData.[Template_Name].Column
lngDocumentNameColumn = wsData.[Document_Name].Column
'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'Create Folder
Dim rootDirectory As String
Dim folderToBeCreated As String
Dim path As String
' Set the root directory path
' where you want to create
' your folder
' Path for MkDir VBA function
' would be the concatination
' of above two
' Check the root directory and folder path
' before creating it directly
If Len(Dir(strDocumentFolder, vbDirectory)) = 0 Then ' full path should
not exist already
VBA.MkDir (strDocumentFolder) ' or VBA.MkDir ("C:\Vishwa\MyFolders\
MyFolder1")
MsgBox "Folder is created successfully"
Else
MsgBox "Folder is already existing in the root directory"
End If
'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With oDoc.PageSetup
.TopMargin = CentimetersToPoints(2)
.LeftMargin = CentimetersToPoints(1.52)
.RightMargin = CentimetersToPoints(1.52)
.BottomMargin = CentimetersToPoints(0.63)
.HeaderDistance = CentimetersToPoints(0.5)
.FooterDistance = CentimetersToPoints(0)
.PaperSize = wdPaperA4
End With
'
Set wsData = Nothing
Set wsControl = Nothing
Set wb = Nothing
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MsgBox ("Letters Completed")
End Sub