Log in

View Full Version : Solved: Can paste.value = documentproperty?



BonnyeLiz
06-13-2005, 08:22 AM
Hi experts across the world! :hi:

You may remember the unbelievably long posts in the past about the If fields in footers to enable a last page footer only. Well, let me just say that Tony's exaple givenin that post worked wonderfully - BUT - only on one module. So, one file numbering system works great within docs based on the template. However, I have found after MUCH battle that the other filenumber for a separate type of document just will not populate correctly.

Now after that babble - I would like to simply cut the filenumber from the document and paste it's value as a document property. This should work, right? So why won't it? Here is what I have so far... If I leave the code alone (yes, even with that horrible Wordbasic bit) the file number populates to the footer of the document, but on every page. So now that the IF Field works well for the path and filename - I figure I should be able to take the contents of the clipboard and the paste value to equal a document property.

Sub AutoNew()

Open "C:\cycomdat\lh_macro.txt" For Input As 1
While Not EOF(1)
Line Input #1, data_$
caseno$ = WordBasic.[Left$](data_$, 10)
If caseno$ = "[{CASENO}]" Then
caseno2$ = Mid(data_$, 11)
WordBasic.Insert caseno2$
Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Font.Size = 7
Selection.Cut
ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = ActiveDocument.PasteAndFormat(wdPasteDefault)
End If
Wend
Close 1
End Sub


Just so you understand (or bang your head in wonder as I have) THIS code works wonderfully for one module only:

Sub AutoNew()

Open "C:\cycomdat\li_macro.txt" For Input As 1
While Not EOF(1)
Line Input #1, data_$
If Left$(data_$, 10) = "[{CASENO}]" Then
ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = Mid(data_$, 11)
End If
Wend
Close 1
End Sub

Aha - simply paste this same code to apply for the other macro text that is read, right? Noooooooo! The one and ONLY difference between the two filenumbers is the text file they read from "li_macro.txt" and "lh_macro.txt".

I have read through the text file and they are both the same information. I have no clue as to why it will not work the same way for both. So back to my secondary solution... How can I adhere the contents of the clipboard value to a word document property? I keep getting 'object not specified' errors and 'object doesn't support this property or method'.

I've fought with this for 3 weeks... I turn to you now for any insights that could help.

Many thanks!
Bonnye :hi:

MOS MASTER
06-13-2005, 10:02 AM
Hi Bonnye, :yes

Well pasting is never gonna work! :rofl: (You can paste into a document but never fill a variable like that)
So as a workarround you could paste to the document and read that back into a string variable and then set that as your variable.

But really you shouldn't wanna do this.
This code of yours should work:

Sub AutoNew()

Open "C:\cycomdat\li_macro.txt" For Input As 1
While Not EOF(1)
Line Input #1, data_$
If Left$(data_$, 10) = "[{CASENO}]" Then
ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = Mid(data_$, 11)
End If
Wend
Close 1
End Sub

My question to you is how have you debuged this?
you can put a debug statement in there like:
Debug.Print Mid(data_$, 11)

If you press CTRL+G the debug window will display the value (if any) that had to written to the property so you no for sure it's not empty.

Otherwise you could call a simple msgbox to have the same value pop-up:
MsgBox Mid(data_$, 11)

Just place them in your code like this:
Sub AutoNew()

Open "C:\cycomdat\li_macro.txt" For Input As 1
While Not EOF(1)
Line Input #1, data_$
If Left$(data_$, 10) = "[{CASENO}]" Then
Debug.Print Mid(data_$, 11)
MsgBox Mid(data_$, 11)
ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = Mid(data_$, 11)
End If
Wend
Close 1
End Sub


So that's just to make sure there is a value.

If there is a value and it still won't stick please come back because there are other ways of filling that property.

Later.:whistle:

BonnyeLiz
06-13-2005, 10:51 AM
Joost,

I receive two msg boxes. The first contains the correct information, the second is blank. Again, no information posts to the Title property of the document. Any idea what would cause the secondary "blank"information?

I profoundly thank you for at least showing me the debug so that I can assure there is truly data being obtained!

Bonnye :cool:

MOS MASTER
06-13-2005, 11:06 AM
Hi Bonnye, :yes

I'm sorry the first one has data and the second one hasn't??

I've only showed you the code for 1 msgbox could you show me the code you've used?

The reason for the box being empty must be in the code or the fact that there is no data in the txtfile in the place of: Mid(data_$, 11)

I'll create some new code for you in a minute as well that you can try...post your code in the meanwhile.

Later..:whistle:

BonnyeLiz
06-13-2005, 11:16 AM
Hello again, Joost :hi:

OK - Here's the code. This is placed in a standard Word template so that when a new doc is created from it, the file number is posted to the word doc property "title". I don't want to infringe on any copywrite issues, but if the text file that the macro reads from would be helpful, by all means let me know and I will send it your way! I just went over the text files line by line to see if I could locate any variance between the two, but nothing yet.

Sub AutoNew()

Open "C:\cycomdat\lh_macro.txt" For Input As 1
While Not EOF(1)
Line Input #1, data_$
If Left$(data_$, 10) = "[{CASENO}]" Then
Debug.Print Mid(data_$, 11)
MsgBox Mid(data_$, 11)
ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) = Mid(data_$, 11)
End If
Wend
Close 1
End Sub

Somehow, the text file that is read is populated based on the specific file opened within the third party software. I wish I could specify which database, but there are numerous ones. That is a completely different area for which I am clueless. :dunno

Thanks!
Bonnye :)

MOS MASTER
06-13-2005, 11:22 AM
Hi Bonnye, :yes

No its not neccessary to send over the textfile. I can read this code so It's easy to create a dupe txtfile that fits the requirement. (I've allready got one) :*)

But I do have to understand something.

The code you/I posted has only one msgbox popping up and the other info is going to the debug window.

Could you please explain how it is you have two msgboxes? that's not possible only 1 is called from the code???

It's really vital that there is data in the messageboxes because otherwise it's logic that the title property won't hold anything.

Please do explain about the blank messagebox cause you're losing me...:eek:

MOS MASTER
06-13-2005, 11:32 AM
Okay Bonnye I've got another approach for you! :yes

Please try out this code:
Option Explicit
Sub AutoNew()
Dim sCase$, data_$
Open ThisDocument.Path & "\li_macro.txt" For Input As 1 'test
Do While Not EOF(1)
Line Input #1, data_$
If Left$(data_$, 10) = "[{CASENO}]" Then
sCase = Mid(data_$, 11)

With Application.Dialogs(wdDialogFileSummaryInfo)
.Title = sCase
.Execute
End With
Exit Do
End If
Loop
Close 1

'For test purpose:
MsgBox ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle)
End Sub


See Attachment..you can run it.

BonnyeLiz
06-13-2005, 11:32 AM
Joost,

Welcome to my world! :rotlaugh: That's exactly what has me baffled! The code runs seamlessly, but the first msgbox shows the filenumber (F00-0000), then the second shows nothing and an OK button. When I look at the debug window, the file number shows at the first line, but then there are two blank lines below it. This made me wonder if somehow blank information is being pulled as well?

There is an LH module that has a filenumber beginning with the letter "F". This is the one we're fighting with. As I illustrated in my first post at the top, the Li module works with the very same code perfectly. The file number beggining with an "L" populates as the document property title! No one, and I mean No One, has been able to explain this mystery. My only guess at this point is that there is something within the Lh text file that is causing the blank information to pop up after the filenumber? :wot

I even considered manually entering the letter "F" and using the Li module, but alas the files are numbered differently there :devil:

As dumbfounded as ever,
Bonnye

MOS MASTER
06-13-2005, 11:37 AM
Well I love your World allready! :rofl: :rotlaugh:

Please take a look at my previous post for a alternate method...

Meanwhile send me the template and a textfile so I can test it for you: (I'll send you my mailaddress via PM)

Later...:whistle:

MOS MASTER
06-13-2005, 11:56 AM
Ok..no email then..

Well don't think I can help you any further than the other code I've provided you with.

Somewhere in your code lies the problem. VBA doesn't give you 2 msgboxes when you've only coded 1. (Unless you have a error)

If I could see the code I could probably see where the problem lies but I have to see the total picture the code presented could never give you 2 messageboxes.

Later..:whistle:

BonnyeLiz
06-13-2005, 12:14 PM
:rotlaugh: Joost!

I'm sorry I didn't respond quickly enough... I was testing and re-testing the template and had a secretary test it as well. It works!!!!!

I don't know how the different code made the difference - but I am not questioning what works by any means!

If I were not across the globe, you'd be getting some serious bear hugs right now!

I cannot thank you enough, kind sir! My monday and this ongoing battle have been superbly conquered!

:friends: Thank you, Thank you, Thank you!

:beerchug: Bonnye

MOS MASTER
06-13-2005, 12:20 PM
Hahahhaaha that's rich! :rofl: :rotlaugh:

Well I've been having the same problem you're having in the past with Word 2000 and that's when I've used that code executing the Dialog object. (I think some versions are buggy filling the properties)

Yes indeed a great shame you're so many miles of water away...how I love those "beer hugs" :cloud9:
O well...have to do with: You're welcome! :beerchug: