View Single Post
 
Old 11-22-2018, 08:16 AM
Firemaster Firemaster is offline Windows 7 64bit Office 2010
Novice
 
Join Date: Nov 2018
Posts: 2
Firemaster is on a distinguished road
Default Read text in a file

Good afternoon all, I have posted this elsewhere but think i got a bit lost on that site so i thought i would ask here. I am not a VBA coder at all but need to cokmplete a small task. i have 2 scripts the info from is used in the second. So the first piece of the script is to read the contents of a text file lets start there:

So hopefully this will read a file in the location whcih consists of just a few letters and numbers. Then this will be available to use in the second part of the script. Is there anyway of showing that it has read the file contents like temporarily adding a message box to prove it has read the txt file. At the moment it faills over on the 'open the text file

Function TextFile_PullData()
'PURPOSE: Send All Data From Text File To A String Variable
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
Dim strUser As string

' get the current user name
strUser = CreateObject("WScript.Network").UserName
'or use strUser = CreateObject("WScript.Shell").ExpandEnvironmentStr ings("%USERNAME%")

'File Path of Text File
FilePath = "C:\Users\" & strUser & "\Temp\VFile.txt"

'Determine the next file number available for use by the FileOpen function
TextFile = FreeFile

'Open the text file
Open FilePath For Input As TextFile

'Store file content inside a variable
FileContent = Input(LOF(TextFile), TextFile)

'Close Text File
Close TextFile

'Report Out Text File Contents
MsgBox FileContent

'have the function return the data to the calling code
TextFile_PullData = FileContent
End Function

Second part it takes the Information and adds it to this script in the TextFile_PullData

Sub UpdateSubject() Dim SaveCode As String Dim KeyWord As String Dim objItem As MailItem

KeyWord = "TSD"

SaveCode = TextFile_PullData
Set objItem = GetCurrentItem()
objItem.Subject = "[" + KeyWord + "=" + SaveCode + "] " + objItem.Subject
End Sub

Function GetCurrentItem() As Object Dim objApp As Outlook.Application

Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select

Set objApp = Nothing
End Function
Reply With Quote