Copy Txt from a file and input into script
up vote
0
down vote
favorite
So we now have the below script. Debug highlights OpenTextfile as highlighted in bold
Before it is put into the second part of the update script can we confirm somehow that the text has been read
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").ExpandEnvironmentStrings("%USERNAME%")
'File Path of Text File
FilePath = "C:Users" & strUser & "TempVFile.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
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
vba outlook
add a comment |
up vote
0
down vote
favorite
So we now have the below script. Debug highlights OpenTextfile as highlighted in bold
Before it is put into the second part of the update script can we confirm somehow that the text has been read
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").ExpandEnvironmentStrings("%USERNAME%")
'File Path of Text File
FilePath = "C:Users" & strUser & "TempVFile.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
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
vba outlook
1
The code you posted is not VBScript. Looks more like VBA. Also, what's stopping you from simply replacingSaveCode = InputBox(...)
withSaveCode = TextFile_PullData
?
– Ansgar Wiechers
Nov 19 at 16:15
If you change the question you invalidate the answer already posted. If this is a new question then roll back to the previous version and create a new question post. You may decide to accept the answer for this question if it answered the original question.
– niton
Nov 21 at 17:53
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
So we now have the below script. Debug highlights OpenTextfile as highlighted in bold
Before it is put into the second part of the update script can we confirm somehow that the text has been read
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").ExpandEnvironmentStrings("%USERNAME%")
'File Path of Text File
FilePath = "C:Users" & strUser & "TempVFile.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
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
vba outlook
So we now have the below script. Debug highlights OpenTextfile as highlighted in bold
Before it is put into the second part of the update script can we confirm somehow that the text has been read
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").ExpandEnvironmentStrings("%USERNAME%")
'File Path of Text File
FilePath = "C:Users" & strUser & "TempVFile.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
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
vba outlook
vba outlook
edited Nov 21 at 15:40
asked Nov 19 at 12:36
Craig Parkinson
12
12
1
The code you posted is not VBScript. Looks more like VBA. Also, what's stopping you from simply replacingSaveCode = InputBox(...)
withSaveCode = TextFile_PullData
?
– Ansgar Wiechers
Nov 19 at 16:15
If you change the question you invalidate the answer already posted. If this is a new question then roll back to the previous version and create a new question post. You may decide to accept the answer for this question if it answered the original question.
– niton
Nov 21 at 17:53
add a comment |
1
The code you posted is not VBScript. Looks more like VBA. Also, what's stopping you from simply replacingSaveCode = InputBox(...)
withSaveCode = TextFile_PullData
?
– Ansgar Wiechers
Nov 19 at 16:15
If you change the question you invalidate the answer already posted. If this is a new question then roll back to the previous version and create a new question post. You may decide to accept the answer for this question if it answered the original question.
– niton
Nov 21 at 17:53
1
1
The code you posted is not VBScript. Looks more like VBA. Also, what's stopping you from simply replacing
SaveCode = InputBox(...)
with SaveCode = TextFile_PullData
?– Ansgar Wiechers
Nov 19 at 16:15
The code you posted is not VBScript. Looks more like VBA. Also, what's stopping you from simply replacing
SaveCode = InputBox(...)
with SaveCode = TextFile_PullData
?– Ansgar Wiechers
Nov 19 at 16:15
If you change the question you invalidate the answer already posted. If this is a new question then roll back to the previous version and create a new question post. You may decide to accept the answer for this question if it answered the original question.
– niton
Nov 21 at 17:53
If you change the question you invalidate the answer already posted. If this is a new question then roll back to the previous version and create a new question post. You may decide to accept the answer for this question if it answered the original question.
– niton
Nov 21 at 17:53
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
This is not VBScript because you are defining your variables As <something>
. In VBScript all variables are of type variant.
Anyway, your Sub UpdateSubject
may very well read in the content of the text file, but is does nothing other than show it in a messagebox.
In order to make it return this data instead of just reading it in a local variable that lives only insife that sub, make it a Function
like :
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").ExpandEnvironmentStrings("%USERNAME%")
'File Path of Text File
FilePath = "C:Users" & strUser & "TempVFile.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
Next use that info in the UpdateSubject
subroutine
Sub UpdateSubject()
Dim SaveCode As String
Dim KeyWord As String
Dim objItem As MailItem
Dim FileContent As String
' here, you use the function to pull the content of the text file and store it in
' a local variable called 'FileContent' to use in your inputbox.
FileContent = TextFile_PullData
SaveCode = InputBox("Please enter filecode in the format nnn/nnn", "VisualFiles Auto Save", FileContent)
Set objItem = GetCurrentItem()
KeyWord = "TSD"
objItem.Subject = "[" + KeyWord + "=" + SaveCode + "] " + objItem.Subject
'or skip the inputox alltogether and set the subject directly:
'objItem.Subject = "[" + KeyWord + "=" + FileContent + "] " + objItem.Subject
End Sub
i am getting the following: compile error: sub or function not defined This is on the Sub UpdateSubject() and the line Set objItem = GetCurrentItem()
– Craig Parkinson
Nov 20 at 8:34
@CraigParkinson I never touched your functionGetCurrentItem
because that had nothing to do with the question.. You should leave that in of course ;)
– Theo
Nov 20 at 12:30
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
This is not VBScript because you are defining your variables As <something>
. In VBScript all variables are of type variant.
Anyway, your Sub UpdateSubject
may very well read in the content of the text file, but is does nothing other than show it in a messagebox.
In order to make it return this data instead of just reading it in a local variable that lives only insife that sub, make it a Function
like :
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").ExpandEnvironmentStrings("%USERNAME%")
'File Path of Text File
FilePath = "C:Users" & strUser & "TempVFile.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
Next use that info in the UpdateSubject
subroutine
Sub UpdateSubject()
Dim SaveCode As String
Dim KeyWord As String
Dim objItem As MailItem
Dim FileContent As String
' here, you use the function to pull the content of the text file and store it in
' a local variable called 'FileContent' to use in your inputbox.
FileContent = TextFile_PullData
SaveCode = InputBox("Please enter filecode in the format nnn/nnn", "VisualFiles Auto Save", FileContent)
Set objItem = GetCurrentItem()
KeyWord = "TSD"
objItem.Subject = "[" + KeyWord + "=" + SaveCode + "] " + objItem.Subject
'or skip the inputox alltogether and set the subject directly:
'objItem.Subject = "[" + KeyWord + "=" + FileContent + "] " + objItem.Subject
End Sub
i am getting the following: compile error: sub or function not defined This is on the Sub UpdateSubject() and the line Set objItem = GetCurrentItem()
– Craig Parkinson
Nov 20 at 8:34
@CraigParkinson I never touched your functionGetCurrentItem
because that had nothing to do with the question.. You should leave that in of course ;)
– Theo
Nov 20 at 12:30
add a comment |
up vote
0
down vote
This is not VBScript because you are defining your variables As <something>
. In VBScript all variables are of type variant.
Anyway, your Sub UpdateSubject
may very well read in the content of the text file, but is does nothing other than show it in a messagebox.
In order to make it return this data instead of just reading it in a local variable that lives only insife that sub, make it a Function
like :
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").ExpandEnvironmentStrings("%USERNAME%")
'File Path of Text File
FilePath = "C:Users" & strUser & "TempVFile.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
Next use that info in the UpdateSubject
subroutine
Sub UpdateSubject()
Dim SaveCode As String
Dim KeyWord As String
Dim objItem As MailItem
Dim FileContent As String
' here, you use the function to pull the content of the text file and store it in
' a local variable called 'FileContent' to use in your inputbox.
FileContent = TextFile_PullData
SaveCode = InputBox("Please enter filecode in the format nnn/nnn", "VisualFiles Auto Save", FileContent)
Set objItem = GetCurrentItem()
KeyWord = "TSD"
objItem.Subject = "[" + KeyWord + "=" + SaveCode + "] " + objItem.Subject
'or skip the inputox alltogether and set the subject directly:
'objItem.Subject = "[" + KeyWord + "=" + FileContent + "] " + objItem.Subject
End Sub
i am getting the following: compile error: sub or function not defined This is on the Sub UpdateSubject() and the line Set objItem = GetCurrentItem()
– Craig Parkinson
Nov 20 at 8:34
@CraigParkinson I never touched your functionGetCurrentItem
because that had nothing to do with the question.. You should leave that in of course ;)
– Theo
Nov 20 at 12:30
add a comment |
up vote
0
down vote
up vote
0
down vote
This is not VBScript because you are defining your variables As <something>
. In VBScript all variables are of type variant.
Anyway, your Sub UpdateSubject
may very well read in the content of the text file, but is does nothing other than show it in a messagebox.
In order to make it return this data instead of just reading it in a local variable that lives only insife that sub, make it a Function
like :
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").ExpandEnvironmentStrings("%USERNAME%")
'File Path of Text File
FilePath = "C:Users" & strUser & "TempVFile.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
Next use that info in the UpdateSubject
subroutine
Sub UpdateSubject()
Dim SaveCode As String
Dim KeyWord As String
Dim objItem As MailItem
Dim FileContent As String
' here, you use the function to pull the content of the text file and store it in
' a local variable called 'FileContent' to use in your inputbox.
FileContent = TextFile_PullData
SaveCode = InputBox("Please enter filecode in the format nnn/nnn", "VisualFiles Auto Save", FileContent)
Set objItem = GetCurrentItem()
KeyWord = "TSD"
objItem.Subject = "[" + KeyWord + "=" + SaveCode + "] " + objItem.Subject
'or skip the inputox alltogether and set the subject directly:
'objItem.Subject = "[" + KeyWord + "=" + FileContent + "] " + objItem.Subject
End Sub
This is not VBScript because you are defining your variables As <something>
. In VBScript all variables are of type variant.
Anyway, your Sub UpdateSubject
may very well read in the content of the text file, but is does nothing other than show it in a messagebox.
In order to make it return this data instead of just reading it in a local variable that lives only insife that sub, make it a Function
like :
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").ExpandEnvironmentStrings("%USERNAME%")
'File Path of Text File
FilePath = "C:Users" & strUser & "TempVFile.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
Next use that info in the UpdateSubject
subroutine
Sub UpdateSubject()
Dim SaveCode As String
Dim KeyWord As String
Dim objItem As MailItem
Dim FileContent As String
' here, you use the function to pull the content of the text file and store it in
' a local variable called 'FileContent' to use in your inputbox.
FileContent = TextFile_PullData
SaveCode = InputBox("Please enter filecode in the format nnn/nnn", "VisualFiles Auto Save", FileContent)
Set objItem = GetCurrentItem()
KeyWord = "TSD"
objItem.Subject = "[" + KeyWord + "=" + SaveCode + "] " + objItem.Subject
'or skip the inputox alltogether and set the subject directly:
'objItem.Subject = "[" + KeyWord + "=" + FileContent + "] " + objItem.Subject
End Sub
answered Nov 19 at 16:35
Theo
2,8861518
2,8861518
i am getting the following: compile error: sub or function not defined This is on the Sub UpdateSubject() and the line Set objItem = GetCurrentItem()
– Craig Parkinson
Nov 20 at 8:34
@CraigParkinson I never touched your functionGetCurrentItem
because that had nothing to do with the question.. You should leave that in of course ;)
– Theo
Nov 20 at 12:30
add a comment |
i am getting the following: compile error: sub or function not defined This is on the Sub UpdateSubject() and the line Set objItem = GetCurrentItem()
– Craig Parkinson
Nov 20 at 8:34
@CraigParkinson I never touched your functionGetCurrentItem
because that had nothing to do with the question.. You should leave that in of course ;)
– Theo
Nov 20 at 12:30
i am getting the following: compile error: sub or function not defined This is on the Sub UpdateSubject() and the line Set objItem = GetCurrentItem()
– Craig Parkinson
Nov 20 at 8:34
i am getting the following: compile error: sub or function not defined This is on the Sub UpdateSubject() and the line Set objItem = GetCurrentItem()
– Craig Parkinson
Nov 20 at 8:34
@CraigParkinson I never touched your function
GetCurrentItem
because that had nothing to do with the question.. You should leave that in of course ;)– Theo
Nov 20 at 12:30
@CraigParkinson I never touched your function
GetCurrentItem
because that had nothing to do with the question.. You should leave that in of course ;)– Theo
Nov 20 at 12:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374814%2fcopy-txt-from-a-file-and-input-into-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The code you posted is not VBScript. Looks more like VBA. Also, what's stopping you from simply replacing
SaveCode = InputBox(...)
withSaveCode = TextFile_PullData
?– Ansgar Wiechers
Nov 19 at 16:15
If you change the question you invalidate the answer already posted. If this is a new question then roll back to the previous version and create a new question post. You may decide to accept the answer for this question if it answered the original question.
– niton
Nov 21 at 17:53