Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Menus and Toolbars / January 2005

Tip: Looking for answers? Try searching our database.

Sharing templates which contain VB code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin J Prince - 17 Jan 2005 22:37 GMT
Greetings,

You may or may not have seen my thread 'Adding a number to a word
document' to which I got a good answer from a member of the NG.

However I still have a slight problem, the solution given does not allow
the template to be shared on other computers.

Review:
I need to have a template with an incremental number each time a 'new'
is created. This template needs to be available to a maximum of 4
computers on a Peer to Peer network. All using XP pro. The server/main
computer has been setup using the suggested AutoNew() and works
correctly.

I have set the remaining PC's word options templates to point at a
shared area on the server/main computer.

But they always fail.

The link for the AutoNew suggestion is
http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm

Please can anyone suggest what I can do to change the macro/template so
that each PC works off the same numbers.txt file?

Many thanks, I look forward to your suggestions

Regards

Signature

Kevin J Prince

Jay Freedman - 18 Jan 2005 01:08 GMT
Hi Kevin,

What happens (or doesn't happen) when the attempt fails? If there's an
error message, what is the exact text of the message?

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Greetings,
>
[quoted text clipped - 25 lines]
>
>Regards
Kevin J Prince - 18 Jan 2005 08:10 GMT
Will pop into work later and get the required information

Thanks for the reply

Kevin

>Hi Kevin,
>
[quoted text clipped - 35 lines]
>>
>>Regards

Signature

Kevin J Prince

Kevin J Prince - 18 Jan 2005 14:31 GMT
The error I get is as follows:

Runtime Error '-2147467259 (80004005)
method 'PrivateProfileString' of object 'system' failed

The template with the VB code in runs fine on the computer which is
installed.

I got the same error whether I had \\maincomp\commontemplates

or

mapped to T:\

Hope this information can shed some light

Regards
Kevin

>Hi Kevin,
>
[quoted text clipped - 35 lines]
>>
>>Regards

Signature

Kevin J Prince

Jay Freedman - 18 Jan 2005 15:37 GMT
Hi Kevin,

OK, next batch of questions: In the PrivateProfileString statement that
fails, what is the path of the text file that should hold the next number?
Is it on the same server as the template? Do the users have access rights to
that location? Does the file exist, and can the users open it with NotePad?

If the file is available but PrivateProfileString refuses to work with it,
it may be necessary to replace PrivateProfileString with other (less
convenient but more reliable) code.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> The error I get is as follows:
>
[quoted text clipped - 54 lines]
>>>
>>> Regards
Kevin J Prince - 18 Jan 2005 16:16 GMT
>Hi Kevin,
>
>OK, next batch of questions: In the PrivateProfileString statement that
>fails, what is the path of the text file that should hold the next
>number?
In test 1 it was
C:\Data\numbers.txt
in test 2 it was
\\maincomp\Data\number.txt

>Is it on the same server as the template?
The server (maincomp) has the template in a folder called

Template is on  C:\Data\common templates\quote.dot
&
Number is on C:\Data\number.txt

>Do the users have access rights to that location?
It is a shared folder and users have write permissions set to yes.

>Does the file exist, and can the users open it with NotePad?

Not tried that, I'll check on my next visit in.

>If the file is available but PrivateProfileString refuses to work with
>it, it may be necessary to replace PrivateProfileString with other
>(less convenient but more reliable) code.
>
>--

So from you final para, it looks like I might end up using a standard
'Open/read/modify/save/close' piece of code instead of the
privateProfileString code.???

My only concern there is how do I address the locations in the actual
code. Would I have to use \\servername\Data\number.txt? Or is there a
better method of addressing?

Regards
Kevin
Signature

Kevin J Prince

Jay Freedman - 18 Jan 2005 18:56 GMT
Hi Kevin,

I don't think the "C:\..." form is going to work. Since VBA is running on
each user's local PC, that path would point to the local C: drive, not the
server's C: drive. The form that uses the server's name (called Universal
Naming Convention or UNC) should work if you get it right. The second
section, Data, needs to be the name of the share, which may or may not be
the same as the name of the folder.

Open Windows Explorer (the file manager, not Internet Explorer) and type on
the Address line
   \\maincomp\Data
If it shows you the contents of that folder, including the number.txt file,
then the share name is also Data. Then you should be able to double-click it
and have it appear in NotePad.

If you have to use other functions instead of PrivateProfileString, they
would be the Open statement (note this is not the same as the Documents.Open
method), Line Input # statement, Print # statement, and Close statement. You
would use the UNC name of the file in the Open statement. Samples available
on request. :-)

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

>> Hi Kevin,
>>
[quoted text clipped - 36 lines]
> Regards
> Kevin
Jay Freedman - 19 Jan 2005 02:20 GMT
Hi Kevin,

Here's some code that will replace the use of PrivateProfileString for
the macro in http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm, and
it should behave better when the data file is on the server.

Private Const IniFile = "\\maincomp\Data\number.txt"

Private Property Get NextNumber() As String
   Dim temp As String
   On Error GoTo BadInput
   Open IniFile For Input As #1
   Line Input #1, temp
   Close #1
   NextNumber = temp
   Exit Property
BadInput:
   NextNumber = "" ' default
End Property

Private Property Let NextNumber(myNumber As String)
   On Error GoTo BadOutput
   Open IniFile For Output As #1
   Print #1, myNumber
   Close #1
   Exit Property
BadOutput:
   MsgBox Prompt:="Unable to store invoice number in" _
       & vbCr & IniFile & vbCr & "Check that it's available.", _
       Title:="File Error"
End Property

Public Sub AutoNew()
   Dim Order As Variant
   
   Order = NextNumber
   
   If Order = "" Then
       Order = 1
   Else
       Order = Order + 1
   End If

   NextNumber = Order
   
   ActiveDocument.Bookmarks("Order").Range.InsertBefore _
       Format(Order, "00#")
   ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Hi Kevin,
>
[quoted text clipped - 17 lines]
>would use the UNC name of the file in the Open statement. Samples available
>on request. :-)
Kevin J Prince - 19 Jan 2005 23:13 GMT
Thanks Jay,

Working on it now at home... now I have my other computer working...

Will let you know how I get on.

Kevin

>Hi Kevin,
>
[quoted text clipped - 72 lines]
>>would use the UNC name of the file in the Open statement. Samples available
>>on request. :-)

Signature

Kevin J Prince

Kevin J Prince - 20 Jan 2005 00:08 GMT
Jay,

It is finding the value, but is unable to print the revised value back
and then it fails on the error BadOutput.
However I can, using the defined path open the number.txt file in
explorer.

I'm very puzzled.

It inserts the number into the word document as an incremented one.

Therefore it's just the output that has a problem..

Scratching head profusely

Regards

Kevin

>Thanks Jay,
>
>Working on it now at home... now I have my other computer working...
>
>Will let you know how I get on.

Signature

Kevin J Prince

Jay Freedman - 20 Jan 2005 01:46 GMT
Hi Kevin,

As the first step in troubleshooting, insert an apostrophe at the
beginning of the line "On Error GoTo BadOutput" -- that will turn the
line into a comment. Then use the macro again, and you'll get a more
specific error message. Post back with the exact text of that error.
(The "On Error" statement traps various kinds of errors, but the way I
wrote it will mask the actual cause. Commenting it out lets the real
error be displayed.)

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Jay,
>
[quoted text clipped - 20 lines]
>>
>>Will let you know how I get on.
Kevin J Prince - 20 Jan 2005 08:50 GMT
Jay once again thanks for taking the time with me

OK I get ........

Runtime error '75':
Path/File access error.

But how can that be when I have just opened it and read the number then
closed it?

Back to you ...

Regards
Kevin

>Hi Kevin,
>
[quoted text clipped - 35 lines]
>>>
>>>Will let you know how I get on.

Signature

Kevin J Prince

Kevin J Prince - 20 Jan 2005 11:43 GMT
Update:

If I transfer the const to the explorer entry bar and press enter it
opens the file,
If I then change it, say from 123 to 124 the try to save it I get the
following error...

'Cannot create the \\main\C\numbers\number.txt file.
Make sure that the path and filename are correct.'

Which they are! (Correct that is)

These tests are on a different setup from works..... hence the different
constant.

I change the folder attributes to (un-tick the read only box) supposedly
allowing me to write the file back... which it allows me to do, But when
I next look at the properties, they are back to having read-only ticked.

The drive properties have : Share this folder on the network- ticked
& Allow Network users to change my files- unticked.
But
The Numbers folder is shared with properties
 Share this folder on the network ticked
 Allow Network users to change my files ticked.

Which I assume allows that folder to have it's files changed.??

I have tried it in a standard folder on the root of the drive and also
in
Documents and Settings\All Users\Documents\numbers

If I do anything manually in the later I can create and modify files
with no problems.

So where do I go from here?

All I can say is AAArrrrggghhhhh!!!!!!!!

Cheers again

Kevin

>Jay once again thanks for taking the time with me
>
[quoted text clipped - 50 lines]
>>>>
>>>>Will let you know how I get on.

Signature

Kevin J Prince

Jay Freedman - 20 Jan 2005 15:32 GMT
Hi Kevin,

Now you're getting into territory where my knowledge is pretty thin. You may
have to ask the folks in the Wiindows XP newsgroups for some help.

Two things could be happening, and I don't know how to find out or fix them:

- The folder access permissions may be set to allow you to read files but
not to modify them. As far as I can tell, Windows XP handles folder
permissions differently when you're in a workgroup than when you're in a
domain, so that complicates the comparison of your home and work
environments.

- Something (I don't know what) may be marking the file as read-only. This
is a separate consideration from the folder access permissions.

Whatever it is, it isn't specific to Word or to VBA (I assume you were using
NotePad to change the number).

The only KnowledgeBase article I could find that refers to the access error
message is clearly not applicable: http://support.microsoft.com/?kbid=197486
talks about resources on a Windows 95 machine.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Update:
>
[quoted text clipped - 95 lines]
>>>>>
>>>>> Will let you know how I get on.
Kevin J Prince - 20 Jan 2005 16:16 GMT
Jay,

Thanks for the information:

From your vast experience have you any idea which would be the best
group to ask my question in. There seems to be a large selection of XP
based NG's some of which I have had a quick look in, but do not seem
appropriate... Ah what the heck, I can only get flamed a few times.GRIN.

So I'll start in  microsoft.public.windowsxp.general a go.

Thanks for all your help so far

Cheers Kevin

>Hi Kevin,
>
[quoted text clipped - 18 lines]
>message is clearly not applicable: http://support.microsoft.com/?kbid=197486
>talks about resources on a Windows 95 machine.

Signature

Kevin J Prince

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.