Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB Script  Outlook

Posted on 2011-10-19
8
Medium Priority
?
310 Views
Last Modified: 2012-06-27
I am building an Outlook form that has several Combo Boxes that i intend to populate from >CSV files. I have written the follow VB code that work great but VBScript is not liking the Line -- Open wFname For Input As wFileNum

I have removed the extra declarations and replaced the variable with #1 . It tells me that end of line is expected.

Any general direction would be great.

Thanks


Public Sub ReadCategoryText()
Dim wFname As String
Dim wStr As String
Dim wFileNum As Integer
wFname = "c:\KACEData\Category.csv"
wFileNum = FreeFile()
Open wFname For Input As wFileNum
  Do While Not EOF(wFileNum)
        Line Input #wFileNum, wStr
    Loop
    Close wFileNum
End Sub
0
Comment
Question by:ChuckRush
  • 3
  • 3
  • 2
8 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36998928
Wfname is Defined as string ,.. Set it as object

Chris
0
 
LVL 76

Expert Comment

by:David Lee
ID: 36998960
Hi, ChuckRush.

If I remember correctly VBScript doesn't support the "Open Filename For Input" syntax.  You have to use the FileSystemObject to read a file.  Something like this.
Sub ReadCategoryText()
	Const ForReading = 1
	Dim objFSO, objFile, wStr
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile("c:\KACEData\Category.csv", ForReading)
	Do While Not objFile.AtEndOfStream
		wStr = objFile.ReadLine
	Loop
	objFile.Close
	Set objFile = Nothing
	Set objFSO = Nothing
End Sub

Open in new window

0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 36998991
Since the declarations included typing I assumed it is a vba script rather than vbs!

Nice to see you again David ... I'm not so active here these days so don't cross your path very often it seems.

Chris
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 76

Expert Comment

by:David Lee
ID: 36999015
Hey, Chris.

For some unfathomable reason Microsoft decided to use VBS for forms and VBA elsewhere.  It's confusing.  Since the author says the code is in a form it'd have to be VBS which, as you noted, doesn't support typing.

Good to see you too.  I've not been as active on EE either.  Hope all is well with you.
0
 

Author Comment

by:ChuckRush
ID: 36999719
Chris

Yes this is VBS. I have no issue writing this in VBA. I used your example and it does read thru the file I added the populate line (which works fine in VBA). THe runtime says it needs an object. I realize i am just not understanding the VBS model yet . I am studying Sue Mosher's book but my mistake is not clear.
THanks

Sub ReadCategoryText()
      Const ForReading = 1
      Dim objFSO, objFile, wStr
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      Set objFile = objFSO.OpenTextFile("c:\KACEData\Category.csv", ForReading)
      Do While Not objFile.AtEndOfStream
      '      wStr = objFile.ReadLine
            cmbCategory.AddItem wStr
      Loop
      objFile.Close
      Set objFile = Nothing
      Set objFSO = Nothing
End Sub
0
 

Author Comment

by:ChuckRush
ID: 36999789
Chris
the ' is removed from the line :       wStr = objFile.ReadLine
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 37000351
You're using DAvids code at this point...

I would wonder if cmbCategory is in scope for the function ... does it work without error if that line is commented out ... or is it readline one you commented out that fails?

Also are you sure of the filename ... if it isn't found then it will fail to instantiate objFile.

Chris
0
 

Author Closing Comment

by:ChuckRush
ID: 37000526
Thanks Chris your example allowed me to figure it all out.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I came across an unsolved Outlook issue and here is my solution.
MS Outlook undoubtedly is the most widely used email client.Its user-friendliness, cost effectiveness, and availability with Microsoft Office Suite make it the most popular email application.  Its compatibility with Microsoft applications like Exch…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question