I am seeking advise / assistance with my script I have put together from tips online and am phased with one last issue that I am having no success with.
All information from row 4 - 8 to be moved up underneath row 3 next to my logo. Now because of the logo row height, it is causing row 4 - 8 to drop below the logo's row. I have been trying to split / merge columns to no success. Please see picture below.
Here is the code i have been mashing at:
On Error goto 0
Const END_OF_STORY = 6
Set objSysInfo = CreateObject("ADSystemInfo")
' ########### This section connects to Active Directory as the currently logged on user
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
sLogoLocation = "\\servername\pic\Sig\logo.jpg"
sStripeLocation = "\\servername\pic\Sig\candystripe.gif"
sLinkAddress = "http://www.yourwebsite.com"
sDisplayLinkText = "www.yourwebsite.com"
sBoldSloganText = "BOLD TEXT USED FOR SLOGAN"
sNormalSloganText = "NORMAL TEXT USED FOR SLOGAN"
' ########### This section sets up the variables we want to call in the script (items on the left; whereas the items on the right are the active directory database field names) - ie strVariablename = objuser.ad.databasename
strGiven = objuser.givenName
strSurname = objuser.sn
strAddress1 = objUser.streetaddress
strAddress1EXT = objUser.postofficebox
strAddress2 = objuser.l
strAddress3 = objuser.st
strPostcode = objuser.postalcode
strCountry = objuser.c
strFax = objuser.facsimileTelephoneNumber
strMobile = objuser.mobile
strTitle = objUser.Title
strDepartment = objUser.Department
strCompany = objUser.Company
strPhone = objUser.telephoneNumber
strEmail = objuser.mail
strWeb = objuser.wWWHomePage
strNotes = objuser.info
strExt = objuser.ipPhone
strDDI = objuser.homephone
strEmailTEXT = "Email: "
strOffice = objuser.physicalDeliveryOfficeName
strPOBOx = objuser.PostOfficeBox
' ########### Sets up word template
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.Style = "No Spacing"
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
' ########### Separate main logo from other tables in the script in its own singular column.
' ########### Calls the variables from above section and inserts into word template, also sets initial font typeface, colour etc.
on error resume next
Const wdAlignParagraphRight = 2
Const NUMBER_OF_ROWS = 8
Const NUMBER_OF_COLUMNS = 3
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS
Set objTable = objDoc.Tables(1)
objTable.Cell(1, 1).Width = "3"
objTable.Cell(2, 1).Width = "3"
objTable.Cell(1, 2).Width = "15"
objTable.Cell(2, 2).Width = "15"
objTable.Rows(1).Range.Font.Bold = true
'objTable.Cell(1, 1).Range.Text = ""
objTable.Cell(1, 2).Range.Text = objuser.givenName & " " & objuser.sn & " | " & objuser.Title & " | " & objuser.Department
objTable.Cell(2, 2).Range.InlineShapes.AddPicture(sStripeLocation)
objTable.Cell(3, 1).Width = "3"
objTable.Cell(3, 2).Width = "15"
objTable.Cell(4, 1).Width = "3"
objTable.Cell(4, 2).Width = "10"
objTable.Cell(4, 3).Width = "10"
objTable.Cell(5, 1).Width = "3"
objTable.Cell(5, 2).Width = "15"
objTable.Cell(6, 1).Width = "3"
objTable.Cell(7, 1).Width = "3"
objTable.Cell(8, 1).Width = "3"
objTable.Rows(3).Range.Font.Bold = false
objTable.Rows(4).Range.Font.Bold = false
objTable.Rows(5).Range.Font.Bold = false
objTable.Rows(6).Range.Font.Bold = false
'objTable.Rows(3).Cells(1).Split 1, 5
'objTable.Rows(3).Cells(3).Split 1, 2
objTable.Cell(5, 2).Merge objTable.Cell(5, 8)
objTable.Cell(3, 2).Merge objTable.Cell(3, 6)
objTable.Cell(4, 2).Merge objTable.Cell(4, 6)
objTable.Cell(6, 2).Merge objTable.Cell(6, 6)
objTable.Cell(3, 1).Range.InlineShapes.AddPicture(sLogoLocation)
objTable.Cell(3, 2).Range.Text = "SwitchBoard: " & objuser.TelephoneNumber & " | " & "Extension: " & objuser.physicalDeliveryOfficeName
objTable.Cell(4, 2).Range.Text = "Fax Number: " & objuser.facsimileTelephoneNumber & " | " & "Mobile: " & objuser.Mobile
objTable.Cell(5, 2).Range.Text = "Address: " & objUser.streetaddress & ", " & objuser.l & ", " & objuser.postalcode & ", " & objuser.st & ", " & objuser.c
objTable.Cell(6, 2).Range.Text = "P.O Box: " & objuser.PostOfficeBox
Set objCell = objTable.Cell(7, 2)
Set objCellRange = objCell.Range
objCell.Select
objSelection.TypeText "Website: "
Set objLink = objSelection.Hyperlinks.Add(objSelection.Range, "http://www.mycompany.com", , , "www.mycompany.com")
Set objCell = objTable.Cell(8, 2)
Set objCellRange = objCell.Range
objCell.Select
objSelection.TypeText "E-mail: "
Set objLink = objSelection.Hyperlinks.Add(objSelection.Range, "mailto: " & strEmail, , , strEmail)
objLink.Range.Font.Name = "Verdana"
objLink.Range.Font.Size = 8
objLink.Range.Font.Bold = false
objSelection.Font.Color = RGB (000,045,154)
objSelection.EndKey END_OF_STORY
objSelection.TypeParagraph()
' ####### Used Exchange 2007 for the disclaimer text to ensure all email is covered (this script forces the user to use this as the default signature, it does not however prevent them from selecting another one when writing an email. Would recommend taking a similar approach to cover yourselves.
' ########### Tells outlook to use this signature for new messages and replys. Signature is called Email Signature.
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Email Signature", objSelection
objSignatureObject.NewMessageSignature = "Email Signature"
'objSignatureObject.ReplyMessageSignature = "Email Signature"
objDoc.Saved = True
objWord.Quit
Related
I have several .xlsm templates in a folder. I'm trying to read through all the excel files in that folder and based on the type of the file, it reads through all the sheets in each file and copy specific cells into another my active workbook (ThisWorkbook).
Following is my code and it is working correctly. However it is super slow. I'm looking for any solution that can speed up the code. I've already tried Application.ScreenUpdating = False but still it is very slow. It takes about 10 min for 20 files to be processed.
DO you guys have any suggestion on how to increase the speed.
Thanks Veru mich in Advance
...
Application.ScreenUpdating = False
FileType = "*.xls*"
OutputRow = 5
Range("$B$6:$M$300").ClearContents
filepath = Range("$B$3") & "\"
ThisWorkbook.ActiveSheet.Range("B" & OutputRow).Activate
OutputRow = OutputRow + 1
Curr_File = Dir(filepath & FileType)
Do Until Curr_File = ""
Set FldrWkbk = Workbooks.Open(filepath & Curr_File, False, True)
ThisWorkbook.ActiveSheet.Range("B" & OutputRow) = Curr_File
OutputRow = OutputRow
For Each sht In FldrWkbk.Sheets
ThisWorkbook.ActiveSheet.Range("C" & OutputRow) = sht.Name
If Workbooks(Curr_File).Worksheets(sht.Name).Range("B7") = "Project Number" Then
For i = 1 To 4
If IsEmpty(Workbooks(Curr_File).Worksheets(sht.Name).Cells(10, 5 + 2 * i)) = False Then
With Workbooks(Curr_File).Worksheets(sht.Name)
MyE = .Cells(10, 5 + 2 * i).Value
MyF = .Cells(11, 5 + 2 * i).Value
End With
With ThisWorkbook.ActiveSheet
.Range("D" & OutputRow).Value = "Unit Weight"
.Range("E" & OutputRow).Value = MyE
.Range("F" & OutputRow).Value = MyF
End With
OutputRow = OutputRow + 1
End If
Next
OutputRow = OutputRow - 1
ElseIf Workbooks(Curr_File).Worksheets(sht.Name).Range("C6") = "PROJECT NUMBER" Then
With Workbooks(Curr_File).Worksheets(sht.Name)
MyE = .Range("$H$9").Value
MyF = .Range("$B$9").Value
End With
With ThisWorkbook.ActiveSheet
.Range("D" & OutputRow).Value = "Specific Gravity"
.Range("E" & OutputRow).Value = MyE
.Range("F" & OutputRow).Value = MyF
End With
ElseIf Workbooks(Curr_File).Worksheets(sht.Name).Range("C6") = "Project Number" Then
With Workbooks(Curr_File).Worksheets(sht.Name)
MyE = .Range("$E$4").Value
MyF = .Range("$R$4").Value
MyG = .Range("$R$5").Value
End With
With ThisWorkbook.ActiveSheet
.Range("D" & OutputRow).Value = "Sieve & Hydrometer"
.Range("E" & OutputRow).Value = MyE
.Range("F" & OutputRow).Value = MyF
.Range("G" & OutputRow).Value = MyG
End With
ElseIf Workbooks(Curr_File).Worksheets(sht.Name).Range("A6") = "PROJECT NUMBER" Then
ThisWorkbook.ActiveSheet.Range("D" & OutputRow).Value = "Moisture Content"
Last = Workbooks(Curr_File).Worksheets(sht.Name).Cells(Rows.Count, "J").End(xlUp).Row
ThisWorkbook.ActiveSheet.Range("I" & OutputRow).Value =
Workbooks(Curr_File).Worksheets(sht.Name).Cells(Last, 10)
ElseIf Workbooks(Curr_File).Worksheets(sht.Name).Range("C5") = "Project Number" Then
With Workbooks(Curr_File).Worksheets(sht.Name)
MyE = .Range("$H$8").Value
MyF = .Range("$B$8").Value
MyG = .Range("$D$8").Value
End With
With ThisWorkbook.ActiveSheet
.Range("D" & OutputRow).Value = "Atterberg Limits"
.Range("E" & OutputRow).Value = MyE
.Range("F" & OutputRow).Value = MyF
.Range("G" & OutputRow).Value = MyG
End With
ElseIf Workbooks(Curr_File).Worksheets(sht.Name).Range("B5") = "Project Number" Then
With Workbooks(Curr_File).Worksheets(sht.Name)
MyE = .Range("$G$4").Value
MyF = .Range("$E$4").Value
MyG = .Range("$E$5").Value
End With
With ThisWorkbook.ActiveSheet
.Range("D" & OutputRow).Value = "Gradation Size"
.Range("E" & OutputRow).Value = MyE
.Range("F" & OutputRow).Value = MyF
.Range("G" & OutputRow).Value = MyG
End With
End If
OutputRow = OutputRow + 1
Next sht
FldrWkbk.Close SaveChanges:=False
Curr_File = Dir
Loop
Set FldrWkbk = Nothing
Application.ScreenUpdating = True
...
I Just realized that the slow performance is due to the formulations that are written in the excel but are linked to the ranges that are pasted from the Macro code. As it was addressed in the previous stack overflow solutions, I simply added "Application.Calculation = xlCalculationManual" in the beginning of the code and "Application.Calculation = xlCalculationAutomatic" at the end of the code and now it is much much faster.
I hope it is also useful to whom is reading this
I'm creating an automated Outlook signature that gets data from AD. All's going well, but I keep getting whitespace (looks like padding or something) on table cells.
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" + strUser)
strName = objUser.givenName
strSurName = objUser.Sn
strFullName = objUser.Fullname
strTitle = objUser.Title
strAdres = objUser.address
strPhone = objUser.TelephoneNumber
strMob = objUser.Mobile
strEmail = objUser.mail
strMarBoo = objUser.StreetAddress
strMarLinkTxt = objUser.postOfficeBox
strMarLink = objUser.l
strDescription = objUser.Description
strIT = ""
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
objSelection.ParagraphFormat.LineSpacing = 14
objSelection.TypeText "Met vriendelijke groet, "
objSelection.TypeText Chr(11)
objSelection.TypeText Chr(11)
'objSelection.Font.Color = RGB(240,73,6)
objSelection.Font.Bold = True
objSelection.TypeText strFullName
objSelection.Font.Bold = False
objSelection.TypeText Chr(11)
objSelection.Font.Color = RGB(47,84,150)
objSelection.Font.Size = 11
objSelection.TypeText strTitle + Chr(11)
objSelection.Font.Size = 11
objSelection.Font.Color = RGB(47,84,150)
Set objRange = objSelection.Range
objDoc.Tables.Add objRange, 3, 5
Set objTable1 = objDoc.Tables(1)
objTable1.TopPadding = PixelsToPoints(10, True)
objTable1.BottomPadding = PixelsToPoints(10, True)
'Merge cells in col 1
objTable1.Columns(1).Cells.Merge
objTable1.Columns(1).PreferredWidth = 90
objTable1.Columns(2).PreferredWidth = 100
objTable1.Columns(3).PreferredWidth = 150
objTable1.Columns(4).PreferredWidth = 100
objTable1.Columns(5).PreferredWidth = 200
'----------------KOLOM 1------------------------------
objTable1.Cell(1,1).Range.InlineShapes.AddPicture "\\int-vm- pdc\NETLOGON\logo_rondje_oranje_small.png"
'----------------KOLOM 2------------------------------
objTable1.Cell(1,2).Range.Font.Bold = True
objTable1.Cell(1,2).Range.Font.Color = RGB(240,73,6)
objTable1.Cell(2,2).Range.Font.Bold = True
objTable1.Cell(2,2).Range.Font.Color = RGB(240,73,6)
objTable1.Cell(3,2).Range.Font.Bold = True
objTable1.Cell(3,2).Range.Font.Color = RGB(240,73,6)
objTable1.Cell(1,2).Range.Text = "Bezoekadres"
objTable1.Cell(2,2).Range.Text = "Hoofdnummer"
objTable1.Cell(3,2).Range.Text = "Rechtstreeks"
'----------------KOLOM 3------------------------------
objTable1.Cell(1,3).Range.Text = strAdres
objTable1.Cell(2,3).Range.Text = strPhone
objTable1.Cell(3,3).Range.Text = strMob
'----------------KOLOM 4------------------------------
objTable1.Cell(1,4).Range.Font.Bold = True
objTable1.Cell(1,4).Range.Font.Color = RGB(240,73,6)
objTable1.Cell(2,4).Range.Font.Bold = True
objTable1.Cell(2,4).Range.Font.Color = RGB(240,73,6)
objTable1.Cell(3,4).Range.Font.Bold = True
objTable1.Cell(3,4).Range.Font.Color = RGB(240,73,6)
objTable1.Cell(1,4).Range.Text = "Emailadres"
objTable1.Cell(2,4).Range.Text = "Website"
'----------------KOLOM 5------------------------------
Set objCell = objTable1.Cell(1,5).Range
Set objLink = objSelection.Hyperlinks.Add(objCell, "mailto:"&strEmail, , ,strEmail)
Set objCell = objTable1.Cell(2,5).Range
Set objLink = objSelection.Hyperlinks.Add(objCell, "https://www.company.com", , ,"https://www.company.com")
objTable1.Cell(3,5).Range.Text = strDescription
objSelection.EndKey 6
With Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
End With
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Handtekening_2018_extended", objSelection
objSignatureObject.NewMessageSignature = "Handtekening_2018_extended"
objSignatureObject.ReplyMessageSignature = "Handtekening_2018_extended"
objDoc.Saved = True
objWord.Quit
See image for a screenshot of the result:
Already tried setting Font.LineHeight, objTable1.Rows(1).Height, but nothing seems to work.
Anyone knows how to solve this?
Maybe there is some more detailed documentation that I cannot find about styling?
I am getting error 424 on this line, can anyone help me please.
lblprvbal.Text = Val(NewItem.SubItems(11))
Private Sub cmdShow_Click()
'lblTotPur/lblTotPayRet/lblBalance
Dim strShow, mSlNo
Dim rsShow As New ADODB.Recordset
Dim NewItem As Variant
If Trim(txtCustomer.Text) = "" Then
MsgBox "Please select customer to proceed...", vbCritical, POPUP_COMP
Exit Sub
End If
Dim recCnt
pgrPartyLedger.Min = 0
recCnt = 0
'VOUCHMST_P//VNO,DATED,VTYPE,REMARKS,byUser CASH PURCHASE RETURN
strShow = "select Count(*) as mCnt from VOUCHMST A,VOUCHDAT B, Prevbal C "
strShow = strShow & " where A.VNO=B.VNO and B.IDNO=C.obd and (A.REMARKS='CASH SALE RETURN' OR A.REMARKS='CREDIT SALE RETURN' OR A.REMARKS='CREDIT SALE' OR A.REMARKS='CASH SALE' OR A.REMARKS='RECEIPT' OR A.REMARKS='CREDIT NOTE') "
strShow = strShow & " and A.DATED between #" & Format(dtFrom.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and #" & Format(dtTo.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and B.IDNO = '" & Trim(txtCustomerId.Text) & "' "
'strShow = strShow & " order by A.ID,A.DATED,A.VNO"
rsShow.Open strShow, cn
recCnt = rsShow("mCnt")
rsShow.Close
pgrPartyLedger.Max = recCnt + 1
'VOUCHMST_P//VNO,DATED,VTYPE,REMARKS,byUser
strShow = "select A.Id,A.cmnt,A.ADV,A.VNO,A.DATED,B.IDNO,B.IDNAME,B.AMOUNT,B.DR_CR,B.VNARRATION,A.REMARKS,B.CQ_TYPE, B.BANKNAME, B.BANKBRANCH, B.CQ_NO, C.amnt from VOUCHMST A,VOUCHDAT B, Prevbal C "
strShow = strShow & " where A.VNO=B.VNO and B.IDNO=C.obd and (A.REMARKS='CASH SALE RETURN' OR A.REMARKS='CREDIT SALE RETURN' OR A.REMARKS='CREDIT SALE' OR A.REMARKS='CASH SALE' OR A.REMARKS='RECEIPT' OR A.REMARKS='CREDIT NOTE') "
strShow = strShow & " and A.DATED between #" & Format(dtFrom.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and #" & Format(dtTo.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and B.IDNO = '" & Trim(txtCustomerId.Text) & "' "
strShow = strShow & " order by A.ID,A.DATED,A.VNO"
rsShow.Open strShow, cn
Dim mPur, mPayRet, mAnyAdv, mTempVNO
mPur = 0
mPayRet = 0
mAnyAdv = 0
mSlNo = 1
ShowPaymentHeader
Do While Not rsShow.EOF
mTempVNO = rsShow("VNO")
Set NewItem = listViewPayment.ListItems.Add(, "C" & mSlNo, Format(rsShow("DATED"), "dd/MM/yyyy"))
NewItem.SubItems(1) = mTempVNO
NewItem.SubItems(2) = IIf(IsNull(rsShow("IDNAME")), "", CommaFilterText(rsShow("IDNAME"), 1))
NewItem.SubItems(11) = rsShow("amnt")
If Trim(rsShow("REMARKS")) = "CASH SALE" Then
NewItem.SubItems(3) = FormatTakaPaisa(rsShow("AMOUNT"))
NewItem.SubItems(4) = FormatTakaPaisa(rsShow("AMOUNT"))
ElseIf Trim(rsShow("REMARKS")) = "CREDIT SALE" Then
mAnyAdv = ShowPartialAdvance(rsShow("VNO"))
NewItem.SubItems(3) = FormatTakaPaisa(rsShow("AMOUNT") + Val(mAnyAdv))
If Val(mAnyAdv) > 0 Then
NewItem.SubItems(4) = FormatTakaPaisa(mAnyAdv)
Else
NewItem.SubItems(4) = ""
End If
Else
NewItem.SubItems(3) = ""
NewItem.SubItems(4) = FormatTakaPaisa(rsShow("AMOUNT"))
NewItem.SubItems(7) = rsShow("CQ_TYPE")
NewItem.SubItems(8) = rsShow("BANKNAME")
NewItem.SubItems(9) = rsShow("BANKBRANCH")
NewItem.SubItems(10) = rsShow("CQ_NO")
NewItem.SubItems(13) = "" & rsShow("cmnt")
End If
NewItem.SubItems(6) = rsShow("IDNO")
mPur = mPur + Val(NewItem.SubItems(3))
mPayRet = mPayRet + Val(NewItem.SubItems(4))
NewItem.SubItems(5) = rsShow("REMARKS")
NewItem.SubItems(12) = GetVoucherRefNo(mTempVNO)
pgrPartyLedger.Value = mSlNo
mSlNo = mSlNo + 1
rsShow.MoveNext
Loop
rsShow.Close
lblprvbal.Text = Val(NewItem.SubItems(11))
lblTotPur.Caption = FormatTakaPaisa(mPur) + Val(lblprvbal.Text)
lblTotPayRet.Caption = FormatTakaPaisa(mPayRet)
lblBalance.Caption = FormatTakaPaisa(mPur - mPayRet) + Val(lblprvbal.Text)
pgrPartyLedger.Value = 0
End Sub
Looks like lblprvbal isn't an object. Meaning, you don't have a TextBox called lblprvbal in your form, even if you think you do. Maybe because its real name is lblPrvBal? That would be consistent with your other object names. As a side note, you probably don't want to start a TextBox with lbl, which suggests it's a label.
Try below. value in the sub item is null and hence the error.
If IsDBNull(NewItem.SubItems(11)) Then
lblprvbal.Text = ""
Else
lblprvbal.Text = Val(NewItem.SubItems(11))
End If
Check if not NewItem is Nothing.
Thanks for the web site and thanks for taking you time to read this.
I created a signature based on a VBS Script i pulled for numerous web sites online and got the signature almost like i would like it to be, just got a few more tweaks before i stop messing with it. i canĀ“t seem to get the vertical alignment to work. Can you help me out please.
The code is below and the image showing refering to what i need is attached.
i need to move the right side image to the a bottom aligned position
i need to remove the space i have between the blue bar and the table above.
Appriciate the help, i am not a programmer just trying to do my best to automate signatures in outlook.
On Error Resume Next
'Option Explicit
Dim objSysInfo,strUser,objUser,strName,strMail,strWebAddr,strCompany,strDepartment,strStreetAddr,strHomePhone,strIpPhone,strMobile
Dim objWord,objDoc,objSelection,objEmailOptions,objSignatureObject,objSignatureEntries,objLink,strlogoATL,strlogoMA,strlogoBAR
Dim objRange,objTable
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strName = objUser.FirstName &" "& objUser.LastName
strMail = objuser.mail
strWebAddr = objuser.wWWHomePage
strCompany = objuser.Company
strDepartment = objUser.Department
strStreetAddr = objuser.streetaddress
strHomePhone = objuser.HomePhone
strIpPhone = objuser.ipPhone
strMobile = objuser.Mobile
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
objSelection.Style = "No Spacing"
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
'Name of Staff
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "10"
objSelection.Font.Color = RGB(91,91,91)
objSelection.TypeText strName
objSelection.TypeText(Chr(11))
objSelection.TypeParagraph()
'Mail
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "8"
objSelection.Font.Color = RGB(91,91,91)
Set objLink = objSelection.Hyperlinks.Add(objSelection.Range, "mailto: " & strMail, , , strMail)
objSelection.TypeText(Chr(11))
'Tel
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "8"
objSelection.Font.Color = RGB(91,91,91)
objSelection.TypeText "Ext : "& strIpPhone & " " & " "& chr(124) & " Telem" & Chr(243) & "vel : " & strMobile
objSelection.TypeText(Chr(11))
objSelection.TypeParagraph()
'Department
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "8"
objSelection.Font.Color = RGB(0,153,181)
objSelection.TypeText strDepartment
objSelection.TypeText(Chr(11))
'Address
objSelection.Font.Name = "Verdana"
objSelection.Font.Size = "8"
objSelection.Font.Color = RGB(0,153,181)
objSelection.TypeText strStreetAddr
objSelection.TypeText(Chr(11))
objSelection.TypeParagraph()
'Company Contact details
objSelection.Font.Name = "Verdana"
objSelection.Font.Color = RGB(0,153,181)
objSelection.TypeText "Tel : "& strHomePhone & " " & chr(124) & " "
'Web
objSelection.Font.Name = "Verdana"
objSelection.Font.Color = RGB(0,153,181)
set objLink = objSelection.Hyperlinks.Add(objSelection.Range,strWebAddr)
strlogoATL="c:\Utils\Assinatura\ins_atl.jpg"
strlogoMA="c:\Utils\Assinatura\ins_ma.jpg"
strlogoBAR="c:\Utils\Assinatura\ins_bar.jpg"
Set objRange = objSelection.Range
objDoc.Tables.Add objRange, 1, 2
Set objTable = objDoc.Tables(1)
objTable.leftpadding = 0
objTable.rightpadding = 0
objTable.Columns(1).Width = objWord.CentimetersToPoints(12.00)
objTable.Cell(1, 1).Range.InlineShapes.AddPicture(strlogoATL)
objTable.Columns(2).Width = objWord.CentimetersToPoints(12.00)
objTable.Cell(1, 2).Range.ParagraphFormat.Alignment = 2
objTable.Cell(1, 2).Range.VerticalAlignment = wdAlignVerticalCenter
objTable.Cell(1, 2).Range.InlineShapes.AddPicture(strlogoMA)
objSelection.EndKey 6
objSelection.TypeParagraph()
Set objRange = objSelection.Range
objDoc.Tables.Add objRange, 1, 1
Set objTable = objDoc.Tables(2)
objTable.leftpadding = 0
objTable.rightpadding = 0
objTable.Columns(1).Width = objWord.CentimetersToPoints(24.00)
objTable.Cell(1, 1).Range.InlineShapes.AddPicture(strlogoBAR)
objSelection.EndKey 6
objSelection.TypeParagraph()
Set objSelection = objDoc.Range()
objSignatureEntries.Add "ATLANTICO", objSelection
objSignatureObject.NewMessageSignature = "ATLANTICO"
objSignatureObject.ReplyMessageSignature = "ATLANTICO"
objDoc.Saved = True
objWord.Quit
wscript.echo "Uma nova assinatura foi aplicada ao seu Outlook!"
Picture of problem shown below
I have a Word vbscript that sets a company signature. I'm trying to figure out how to add lines before the table and remove the extra lines that are showing up after the table.
Here's the code:
Set objSysInfo = CreateObject("ADSystemInfo")
Set WshShell = CreateObject("WScript.Shell")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
strName = objUser.FullName
strFirst = objUser.FirstName
strLast = objUser.LastName
strInitials = objUser.Initials
strOffice = objUser.physicalDeliveryOfficeName
strPOBox = objUser.postOfficeBox
strTitle = objUser.Description
strCred = objUser.info
strStreet = objUser.StreetAddress
strLocation = objUser.l
strPostCode = objUser.PostalCode
strPhone = objUser.TelephoneNumber
strMobile = objUser.Mobile
strFax = objUser.FacsimileTelephoneNumber
strEmail = objUser.mail
strCompany = objUser.Company
Set objWord = CreateObject("Word.Application")
Const END_OF_STORY = 6
Const NUMBER_OF_ROWS = 1
Const NUMBER_OF_COLUMNS = 2
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature
Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
Set objRange = objDoc.Range()
objDoc.Tables.Add objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS
Set objTable = objDoc.Tables(1)
Dim rngCell
Set rngCell = objTable.Cell(1, 2).Range
objTable.Columns(1).Width = 50
objTable.Columns(2).Width = 360
rngCell.ParagraphFormat.SpaceAfter = 0
rngCell.ParagraphFormat.LineSpacingRule = wdLineSpaceExactly
rngCell.ParagraphFormat.LineSpacing = 12
rngCell.Text = strFirst & " " & strInitials & " " & strLast & " | " & _
strOffice & " | " & strCompany & vbCr
rngCell.Font.Bold = True
rngCell.Font.Name = "Calibri"
rngCell.Font.Size = 10
rngCell.Collapse 0 'wdCollapseEnd
rngCell.MoveEnd 1, -1 'wdCharacter, 1
rngCell.Text = strStreet & " | " & strPOBox & " | " & strLocation & vbCr
rngCell.Font.Bold = False
rngCell.Font.Name = "Calibri"
rngCell.Font.Size = 10
rngCell.Collapse 0 'wdCollapseEnd
rngCell.MoveEnd 1, -1 'wdCharacter, 1
rngCell.Text = vbCr & "Phone: " & strPhone & " | " & "Fax: " & strFax & " | " & "Email: " & vbCr
rngCell.Font.Bold = False
rngCell.Font.Name = "Calibri"
rngCell.Font.Size = 10
rngCell.Collapse 0 'wdCollapseEnd
rngCell.MoveEnd 1, -1 'wdCharacter, 1
Set objLink = objTable.Cell(1, 2).Range
objLink.Hyperlinks.Add rngCell, "mailto:" & strEmail,,,strEmail
objLink.Font.Size = 10
objLink.Font.Name = "Calibri"
objSelection.EndKey END_OF_STORY
objSelection.ParagraphFormat.SpaceAfter = 0
Set objSelection = objDoc.Range()
objSignatureEntries.Add "Reply Signature", objSelection
objSignatureObject.ReplyMessageSignature = "Reply Signature"
objDoc.Saved = True
objWord.Quit
(I removed the logo/image in the first column for security reasons), but for some reason, there are extra lines below the text & logo (when it's there) within the table, and there are extra lines below the table. I need those to disappear if possible? Any help would be greatly appreciated! :)
Thanks!
For adding lines before the table, best to add the lines (paragraphs, I assume) before you insert the table. So something like:
objRange.Text = Chr(13) & Chr(13)
objRange.Collapse 0 'end
Set objTable = objDoc.Tables.Add(objRange, NUMBER_OF_ROWS, NUMBER_OF_COLUMNS)