VBA Workbook name and steppinjg throug the code

ziad alsayed

Well-known Member
Joined
Jul 17, 2010
Messages
665
dear all

the below code is working but i have 2 issues here

1- in am using WBN.name and it is giving the file name with .xls , i need to remove the .xls ( check in red)
2- if i step through the code after i pass the line " Set WBN = Workbooks.Open(Filename:=thisfile)
" the code will run till the end without allowing me to step line by line, how is that happening?

Code:
Sub try()
Dim omail As Object
Dim oapp As Object
Dim Msg As String
Dim WSl As Worksheet
Dim WBN As Workbook
Dim SigString As String
Dim Signature As String
Set WSl = Worksheets.Add(After:=Worksheets("By Sector"))
' list Files from folder, this will get the path of all files from the folder
Call FindFiles2007(Dummy)
' find lastrow
lastrow = WSl.Cells(Rows.Count, 1).End(xlUp).Row
' Loop through all  the files on wsl
For j = 1 To lastrow
    thisfile = WSl.Cells(j, 1)
    Set WBN = Workbooks.Open(Filename:=thisfile)
   
        Set oapp = CreateObject("outlook.application")
        Set omail = oapp.createitem(0)
' add the email Signature
    SigString = "c:\Users\Ziad Alsayed\AppData\Roaming\Microsoft\Signatures\Ziad.htm"
                If Dir(SigString) <> "" Then
                    Signature = GetBoiler(SigString)
                Else
                    Signature = ""
                End If
' start preparing to sned the email
        With omail
            .To = "[EMAIL="imad.elhage@jubailibros.com"]imad.elhage@jubailibros.com[/EMAIL]"
            .cc = "[EMAIL="karim.jubaili@jubailibros.com"]karim.jubaili@jubailibros.com[/EMAIL]"
            .Subject = [COLOR=red]WBN.Name[/COLOR] & " " & "Customer Without Profile" & " " & Format$(Date, "dd ,mmmm,yyyy")
            .attachments.Add WBN.FullName
            Msg = "Dear" & " " & "Imad" & "<br><br>"
            Msg = Msg & "Please find attached file, "
            Msg = Msg & " attached are customer With No Profile, please Contact " & [COLOR=red]WBN.Name[/COLOR] & " to add the profile."
            Msg = Msg & "<br><br>"
            .htmlbody = Msg & "<br><br>" & Signature
            .send
        End With
   ' Close Workbook
   WBN.Close savechanges:=False
 Next j
        
    Set omail = Nothing
    Set oapp = Nothing
    WSl.Delete
End Sub
Function GetBoiler(ByVal sFile As String) As String
'**** Kusleika
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.getfile(sFile).OpenAstextstream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function


Appreciate any help
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try

Code:
.Subject = Left(wbn.Name, InStr(wbn.Name, ".") - 1) & " " & "Customer Without Profile" & " " & Format$(Date, "dd ,mmmm,yyyy")
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top