'PrivateProgramString' of object 'System' failed

S

singeredel

The following autorun code worked in Word 2003/Windows XP:

Sub AutoNew()
InvoiceNo = System.PrivateProfileString("C:\Settings-Hannani.txt",
"MacroSettings", "InvoiceNo")

If InvoiceNo = "" Then
InvoiceNo = "1"
Else
InvoiceNo = InvoiceNo + 1
End If

System.PrivateProfileString("C:\Settings-Hannani.txt", "MacroSettings",
"InvoiceNo") = InvoiceNo

ActiveDocument.Bookmarks("InvoiceNo").Range.InsertBefore
Format(InvoiceNo, "00#")
ActiveDocument.SaveAs FileName:="C:\Hannani\Word Files\Invoices\" +
"Hannani Inv 2008-" & Format(InvoiceNo, "00#")

End Sub

I copied everything over to a new computer running Windows Vista and Word
2007 and get the following error:

"Method 'PrivateProfileString' of object 'System' failed"

This is what appears in the referenced Settings-Hannani.txt file:

[MacroSettings]
InvoiceNo=16

It is used to increment an invoice number each time the template is used to
create a new document.

Can you tell why this does not work in Word 2007?

Thanks...
 
J

Jay Freedman

I suspect that the difference is XP versus Vista, not the version of Word being
used. In Vista, if you're running as an unprivileged user rather than as a
member of the Administrators group, you have limited access to the root folder
of the system drive (usually C:).

Try moving the settings file to some subdirectory that isn't a special location.
I think you'll find that the macro then works the same as in Word 2003.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
S

singeredel

Thank you for your reply. I am the administrator. Would it have to do with
having to add the password or doing some check of privileges? If so, how
would this be written?
--
singeredel


Jay Freedman said:
I suspect that the difference is XP versus Vista, not the version of Word being
used. In Vista, if you're running as an unprivileged user rather than as a
member of the Administrators group, you have limited access to the root folder
of the system drive (usually C:).

Try moving the settings file to some subdirectory that isn't a special location.
I think you'll find that the macro then works the same as in Word 2003.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

The following autorun code worked in Word 2003/Windows XP:

Sub AutoNew()
InvoiceNo = System.PrivateProfileString("C:\Settings-Hannani.txt",
"MacroSettings", "InvoiceNo")

If InvoiceNo = "" Then
InvoiceNo = "1"
Else
InvoiceNo = InvoiceNo + 1
End If

System.PrivateProfileString("C:\Settings-Hannani.txt", "MacroSettings",
"InvoiceNo") = InvoiceNo

ActiveDocument.Bookmarks("InvoiceNo").Range.InsertBefore
Format(InvoiceNo, "00#")
ActiveDocument.SaveAs FileName:="C:\Hannani\Word Files\Invoices\" +
"Hannani Inv 2008-" & Format(InvoiceNo, "00#")

End Sub

I copied everything over to a new computer running Windows Vista and Word
2007 and get the following error:

"Method 'PrivateProfileString' of object 'System' failed"

This is what appears in the referenced Settings-Hannani.txt file:

[MacroSettings]
InvoiceNo=16

It is used to increment an invoice number each time the template is used to
create a new document.

Can you tell why this does not work in Word 2007?

Thanks...
 
S

singeredel

I tried moving the file to various places, including the Microsoft templates
folder, but I get the same error.
--
singeredel


Jay Freedman said:
I suspect that the difference is XP versus Vista, not the version of Word being
used. In Vista, if you're running as an unprivileged user rather than as a
member of the Administrators group, you have limited access to the root folder
of the system drive (usually C:).

Try moving the settings file to some subdirectory that isn't a special location.
I think you'll find that the macro then works the same as in Word 2003.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

The following autorun code worked in Word 2003/Windows XP:

Sub AutoNew()
InvoiceNo = System.PrivateProfileString("C:\Settings-Hannani.txt",
"MacroSettings", "InvoiceNo")

If InvoiceNo = "" Then
InvoiceNo = "1"
Else
InvoiceNo = InvoiceNo + 1
End If

System.PrivateProfileString("C:\Settings-Hannani.txt", "MacroSettings",
"InvoiceNo") = InvoiceNo

ActiveDocument.Bookmarks("InvoiceNo").Range.InsertBefore
Format(InvoiceNo, "00#")
ActiveDocument.SaveAs FileName:="C:\Hannani\Word Files\Invoices\" +
"Hannani Inv 2008-" & Format(InvoiceNo, "00#")

End Sub

I copied everything over to a new computer running Windows Vista and Word
2007 and get the following error:

"Method 'PrivateProfileString' of object 'System' failed"

This is what appears in the referenced Settings-Hannani.txt file:

[MacroSettings]
InvoiceNo=16

It is used to increment an invoice number each time the template is used to
create a new document.

Can you tell why this does not work in Word 2007?

Thanks...
 
J

Jay Freedman

Then I don't know what the problem is. I copied your code into a Word 2007
document on Vista, created the text file in the root folder (for which Vista UAC
required me, even running as an administrator, to confirm), and ran the macro.
It worked perfectly.


I tried moving the file to various places, including the Microsoft templates
folder, but I get the same error.
--
singeredel


Jay Freedman said:
I suspect that the difference is XP versus Vista, not the version of Word being
used. In Vista, if you're running as an unprivileged user rather than as a
member of the Administrators group, you have limited access to the root folder
of the system drive (usually C:).

Try moving the settings file to some subdirectory that isn't a special location.
I think you'll find that the macro then works the same as in Word 2003.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

The following autorun code worked in Word 2003/Windows XP:

Sub AutoNew()
InvoiceNo = System.PrivateProfileString("C:\Settings-Hannani.txt",
"MacroSettings", "InvoiceNo")

If InvoiceNo = "" Then
InvoiceNo = "1"
Else
InvoiceNo = InvoiceNo + 1
End If

System.PrivateProfileString("C:\Settings-Hannani.txt", "MacroSettings",
"InvoiceNo") = InvoiceNo

ActiveDocument.Bookmarks("InvoiceNo").Range.InsertBefore
Format(InvoiceNo, "00#")
ActiveDocument.SaveAs FileName:="C:\Hannani\Word Files\Invoices\" +
"Hannani Inv 2008-" & Format(InvoiceNo, "00#")

End Sub

I copied everything over to a new computer running Windows Vista and Word
2007 and get the following error:

"Method 'PrivateProfileString' of object 'System' failed"

This is what appears in the referenced Settings-Hannani.txt file:

[MacroSettings]
InvoiceNo=16

It is used to increment an invoice number each time the template is used to
create a new document.

Can you tell why this does not work in Word 2007?

Thanks...
 
S

singeredel

Thank you. I have no idea why it doesn't work then.
--
singeredel


Jay Freedman said:
Then I don't know what the problem is. I copied your code into a Word 2007
document on Vista, created the text file in the root folder (for which Vista UAC
required me, even running as an administrator, to confirm), and ran the macro.
It worked perfectly.


I tried moving the file to various places, including the Microsoft templates
folder, but I get the same error.
--
singeredel


Jay Freedman said:
I suspect that the difference is XP versus Vista, not the version of Word being
used. In Vista, if you're running as an unprivileged user rather than as a
member of the Administrators group, you have limited access to the root folder
of the system drive (usually C:).

Try moving the settings file to some subdirectory that isn't a special location.
I think you'll find that the macro then works the same as in Word 2003.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.

On Tue, 16 Sep 2008 14:34:01 -0700, singeredel

The following autorun code worked in Word 2003/Windows XP:

Sub AutoNew()
InvoiceNo = System.PrivateProfileString("C:\Settings-Hannani.txt",
"MacroSettings", "InvoiceNo")

If InvoiceNo = "" Then
InvoiceNo = "1"
Else
InvoiceNo = InvoiceNo + 1
End If

System.PrivateProfileString("C:\Settings-Hannani.txt", "MacroSettings",
"InvoiceNo") = InvoiceNo

ActiveDocument.Bookmarks("InvoiceNo").Range.InsertBefore
Format(InvoiceNo, "00#")
ActiveDocument.SaveAs FileName:="C:\Hannani\Word Files\Invoices\" +
"Hannani Inv 2008-" & Format(InvoiceNo, "00#")

End Sub

I copied everything over to a new computer running Windows Vista and Word
2007 and get the following error:

"Method 'PrivateProfileString' of object 'System' failed"

This is what appears in the referenced Settings-Hannani.txt file:

[MacroSettings]
InvoiceNo=16

It is used to increment an invoice number each time the template is used to
create a new document.

Can you tell why this does not work in Word 2007?

Thanks...
 
J

Jonathan West

I have always found System.PrivateProfileString unreliable and prone to
errors of this kind all the way back to Word 97, and no longer use it.

Instead, I use the CIniFile class module written and publised by Karl
Peterson, available for free from here

http://vb.mvps.org/samples/project.asp?id=kpIni

It does everything that System.PrivateProfileString can do with INI files,
and much, much more.
 
S

singeredel

Thank you for responding. I looked at the link you provided, but not being a
programmer it is Greek to me. Any way you can give me some instructions to
accomplish what was written in the code above using the CIniFile module?

--
singeredel


Jonathan West said:
I have always found System.PrivateProfileString unreliable and prone to
errors of this kind all the way back to Word 97, and no longer use it.

Instead, I use the CIniFile class module written and publised by Karl
Peterson, available for free from here

http://vb.mvps.org/samples/project.asp?id=kpIni

It does everything that System.PrivateProfileString can do with INI files,
and much, much more.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

singeredel said:
The following autorun code worked in Word 2003/Windows XP:

Sub AutoNew()
InvoiceNo = System.PrivateProfileString("C:\Settings-Hannani.txt",
"MacroSettings", "InvoiceNo")

If InvoiceNo = "" Then
InvoiceNo = "1"
Else
InvoiceNo = InvoiceNo + 1
End If

System.PrivateProfileString("C:\Settings-Hannani.txt", "MacroSettings",
"InvoiceNo") = InvoiceNo

ActiveDocument.Bookmarks("InvoiceNo").Range.InsertBefore
Format(InvoiceNo, "00#")
ActiveDocument.SaveAs FileName:="C:\Hannani\Word Files\Invoices\" +
"Hannani Inv 2008-" & Format(InvoiceNo, "00#")

End Sub

I copied everything over to a new computer running Windows Vista and Word
2007 and get the following error:

"Method 'PrivateProfileString' of object 'System' failed"

This is what appears in the referenced Settings-Hannani.txt file:

[MacroSettings]
InvoiceNo=16

It is used to increment an invoice number each time the template is used
to
create a new document.

Can you tell why this does not work in Word 2007?

Thanks...
 
J

Jonathan West

singeredel said:
Thank you for responding. I looked at the link you provided, but not being
a
programmer it is Greek to me. Any way you can give me some instructions to
accomplish what was written in the code above using the CIniFile module?


Place the entire module into the VBA project of your template. Then you can
proceed as follows

Dim INI as CIniFile
Set INI = New CIniFile
InvoiceNo = INI.EntryRead(EntryName:="InvoiceNo", Section:="MacroSettings",
_
FileName:="C:\Settings-Hannani.txt")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top