Re: What is going wrong here?



I'm not sure what this does:

With Dialogs(wdDialogToolsOptionsFileLocations)
.Path = "STARTUP-PATH"
.Update
vStartupPath = .Setting

Are you trying to get the setting of the Startup Path or change it?
The following can be put into a string and will have the path.
Application.Options.DefaultFilePath(wdStartupPath)

What follows is a function that I wrote a while back. It may be a useful
starting point for you.

Function WorkGroupPath() As String
' Written by Charles Kenyon
' February 28, 2003
'
' Used by templates menus to set location of templates.
' Returns workgroup tempates path with "\" at the end.
'
' This is needed because if the folder is a network drive rather
' than a folder, it will have the "\" already. If it is a folder,
' it will not have the backslash. This function gives a string
' with the backslash in either case.
'
WorkGroupPath =
Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath)
If Right(WorkGroupPath, 1) <> "\" Then
WorkGroupPath = WorkGroupPath & "\"
End If
End Function

Try using Application.Options.DefaultFilePath(wdStartupPath) instead.

Note, I am a novice programmer, a lawyer. Generally, though, I use the
dialogs to change settings if needed but not to get information. See the
links under "Working with built-in dialogs" at
http://word.mvps.org/FAQs/MacrosVBA/index.htm.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.



"David" <David@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:11B24638-9EF0-4CCC-8963-FB0A52C04039@xxxxxxxxxxxxxxxx
Thanks for valuable code comments.
Stepping resulted in crash at:
vStartupPath = .Setting
Does this help?

"Charles Kenyon" wrote:

Did you try stepping through it? F8 in the vba Editor.

Notes on your code. You should not have the customization context for
your
changes as normal.dot. Make it your job finisher template or another
Add-In. If it is loaded as an Add-In the button, keyboard shortcut, and
macro will all be available. Once you have made a change through code,
you
should save the template in your code or mark its saved state as True.
Otherwise your user is going to be reading a warning about changes being
made to some template and get annoyed. (If the changes are being made to
normal.dot, the user should be annoyed.)

Generally AddIns are distributed using the user network login script
rather
than through vba.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.


"David" <David@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1AB85A94-3550-4860-8777-5976E7EE6B4B@xxxxxxxxxxxxxxxx
Hi and thanks,
This code works fine in Word97/Win98, and Word2000/XP, but when I try
to
run
it on Word2002/XP or Word2003/XP it crashes Word totally with a
'problem'
in
MSO.dll. According to MSKB, it means corrupted user account, but
creating
and running under a new user gives same results. Here's the code:

'1. Get the startup folder
Dim vStartupPath As String
With Dialogs(wdDialogToolsOptionsFileLocations)
.Path = "STARTUP-PATH"
.Update
vStartupPath = .Setting
If Not Right$(vStartupPath, 1) = "\" Then
vStartupPath = vStartupPath + "\"
End If
End With
'-------------------------------------------------
'2. Check if template is loaded and unload it if so.
If Len(Dir(vStartupPath & "Job Finisher.dot")) > 0 Then
AddIns(vStartupPath & "Job Finisher.dot").Installed = False
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "Normal.dot"
End With
End If
'-------------------------------------------------
'3. Check if file is in C:\Documed\blanks and Copy it to the startup
folder
If Len(Dir("C:\DocuMed\Blanks\Job Finisher.dot")) > 0 Then
FileCopy "C:\DocuMed\Blanks\Job Finisher.dot", vStartupPath & "Job
Finisher.dot"
MsgBox "'Job Finisher.dot' has been copied to the Startup folder.
Click
OK to continue."
Else
MsgBox "'Job Finisher.dot' is not in the C:\Documed\Blanks folder.
Please put it there and reclick the Setup Button."
Exit Sub
End If
'-------------------------------------------------
AddIns.Add FileName:=vStartupPath & "Job Finisher.dot", Install:=True
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = "Normal.dot"
End With
'-------------------------------------------------
'5. Create Toolbar button
CustomizationContext = NormalTemplate
Set isThere = CommandBars("Menu Bar").FindControl _
(Type:=msoControlButton, Tag:="Job Finisher")
If isThere Is Nothing Then
With CommandBars("Menu Bar").Controls
Set myButton = .Add(Type:=msoControlButton)
With myButton
.Style = msoButtonCaption
.Caption = "&Job Finisher"
.OnAction = "JobFinisher"
.Tag = "Job Finisher"
End With
End With
MsgBox "'Job Finisher' button added to menu bar."
Else
MsgBox "Update complete."
Exit Sub
End If
MsgBox "Job Finisher shortcut key set to Alt+J."
End Sub





.



Relevant Pages

  • Re: Macros Disabled
    ... Updating Word from Microsoft's website will not put Add-Ins in your startup ... See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome! ... it out of the Startup folder? ... If you don't want any macros to run, ever, and you don't want to be ...
    (microsoft.public.word.newusers)
  • Re: Question on downloading posts
    ... I've had to load it manually after starting up so far ... on startup automatically in Windows 7. ... doesn't seem to be a "startup" folder anywhere in Win 7, ... and ask them where to put a link to CapsUnlock so that it ...
    (soc.retirement)
  • Re: Document Recovery Error Loop - Word just wont start
    ... If Word starts ok in Safe Mode, then the problem is not with Word but something third party breaking Word. ... > I removed the normal.dot file and checked the Word and Office Startup ... There is nothing in the Word Startup folder and there is no ...
    (microsoft.public.word.application.errors)
  • Re: Like a bad penny
    ... Templates and AddIns but removing them from Word's sight via the File ... The first is your personal Startup ... That will give you an Explorer-type Window ... click on the "Create new folder" icon at the top (towards ...
    (microsoft.public.word.vba.general)