Literally Reading Word Files
rowix
Member Posts: 27
Im having a problem with the following.
In VBA i can read a word document literally by using the word 11.0 automation and the folowing Code
When i try to create this for navision it looks like this:
But this wil result in a crash ](*,) or a not usefull value :-k
When i change var1 from variant to text it results in a compile error text := automation
If anyone has any idea how i can get this to work i will be very
In VBA i can read a word document literally by using the word 11.0 automation and the folowing Code
Dim wapp As Word.Application
Set wapp = CreateObject("Word.Application")
Word.Documents.Open (txtPath)
txtNumberOfWords = (Word.ActiveDocument.Words.Count) - 1
txtPath = Word.ActiveDocument.Words(1)
Word.ActiveDocument.Close
This will result in the first word of the word document.When i try to create this for navision it looks like this:
IF NOT ISCLEAR(WoApp) THEN
CLEAR(WoApp);
CREATE(WoApp);
WoApp.Documents.Open(Path);
Spaces := WoApp.ActiveDocument.Words.Count;
Spaces -= 1; //Delete the begin Space
Var1 := WoApp.ActiveDocument.Words.Item(1);
WoApp.Documents.Close;
MESSAGE('%1',FORMAT(txt1));
In this code Path is the string to filename and Woapp is the word automation.But this wil result in a crash ](*,) or a not usefull value :-k
When i change var1 from variant to text it results in a compile error text := automation
If anyone has any idea how i can get this to work i will be very
0
Answers
-
My advice is to write yourself a wrapper dll, I would recommend in VB. If you just need a word count then add a method for that, such as:
GetWordCount(path as string) as int
or in the case of the first word ..something like:
GetFirstWord(path as string) as string
Navision doesn't handle certain values to well, such as null. Also Navision doesn't allow you to proactively handle errors well either. I always recommend making your wrapper for such purposes and enclose the functionality into methods in your wrapper. Hope this helps.Thad Ryker
I traded my sanity for a railgun
0 -
Try changing you code to be like this ...
IF NOT ISCLEAR(woApp) THEN CLEAR(woApp); CREATE(woApp); ParamFALSE := FALSE; ParamTRUE := TRUE; ParamFile := '..your file path..'; woDoc := woApp.Documents.Open2000(ParamFile,ParamFALSE,ParamTRUE); Spaces := woApp.ActiveDocument.Words.Count; Spaces -= 1; //Delete the begin Space Var1 := woDoc.Words.Item(1).Text; woApp.Documents.Close; woApp.Quit;
0 -
Lin wrote:Try changing you code to be like this ...
IF NOT ISCLEAR(woApp) THEN CLEAR(woApp); CREATE(woApp); ParamFALSE := FALSE; ParamTRUE := TRUE; ParamFile := '..your file path..'; woDoc := woApp.Documents.Open2000(ParamFile,ParamFALSE,ParamTRUE); Spaces := woApp.ActiveDocument.Words.Count; Spaces -= 1; //Delete the begin Space Var1 := woDoc.Words.Item(1).Text; woApp.Documents.Close; woApp.Quit;
lin Thanks for the help the .text; does the trick in my code but what kind of variable is woDoc I thought it was “automation.words” but that will not work.
Kind Regards
Peter0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions