Re: Getting program to work with Word already open... by Jonathan
Jonathan
Wed May 25 11:04:27 CDT 2005
Nothing obvious there. Have you tried opening the VBA editor and pressinbg
the F8 key to step through the code a line at a time to see what happens?
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
"axeman" <axeman@discussions.microsoft.com> wrote in message
news:87E348EA-6050-40BB-8736-34269E9C9BA6@microsoft.com...
> Alright here's the code below. I didn't include the code for the macros
> that
> are called in the Fields() module because they aren't the cause of the
> problem. Any help is greatly appreciated!!!!
>
> BEGIN CODE
> ---------------------------------------------------------------------------------------------
> 'Declare for call to mpr.dll.
> Declare Function WNetGetUser Lib "mpr.dll" _
> Alias "WNetGetUserA" (ByVal lpName As String, _
> ByVal lpUserName As String, lpnLength As Long) As Long
>
> Const NoError = 0 'The Function call was successful
>
>
> Function GetUserName() As String
>
> 'Buffer size for the return string.
> Const lpnLength As Long = 255
>
> 'Get return buffer space.
> Dim status As Integer
>
> 'For getting user information.
> Dim lpName, lpUserName As String
>
> 'Assign the buffer size constant to lpUserName.
> lpUserName = Space$(lpnLength + 1)
>
> 'Get the log-on name of the person using product.
> status = WNetGetUser(lpName, lpUserName, lpnLength)
>
> 'See whether error occurred.
> If status = NoError Then
> 'This line removes the null character. Strings in C are null-
> 'terminated. Strings in Visual Basic are not null-terminated.
> 'The null character must be removed from the C strings to be used
> 'cleanly in Visual Basic.
> lpUserName = Left$(lpUserName, InStr(lpUserName, Chr(0)) - 1)
> End If
>
> 'Display the name of the person logged on to the machine.
> GetUserName = lpUserName
>
> End Function
>
> Sub Offer()
> '
> ' Offer Macro
> '
> Load formOfferLetter
> formOfferLetter.Show
>
> End Sub
>
> Public Sub Fields()
> '
> ' Field Value Updater
> '
> On Error Resume Next
>
> Dim userDesktopDir As String
> Dim OfferLetterName As String
> Dim firstname, lastname As String
>
>
> If formOfferLetter.optMgrToEE.Value = True Then
> Application.Run MacroName:="UpdateFieldsEE"
> End If
>
> If formOfferLetter.optMgrToMgr.Value = True Then
> Application.Run MacroName:="UpdateFieldsMgr"
> End If
>
> If Err.Number = 5152 Then
>
> Err.Clear
> userDesktopDir = "D:\Profiles\" + GetUserName + "\Desktop\Offer
> Letters\"
> firstname = ActiveDocument.FormFields("EEFName1").Result
> lastname = ActiveDocument.FormFields("EELName1").Result
> OfferLetterName = firstname + " " + lastname + " - Offer.doc"
> ActiveDocument.SaveAs FileName:=userDesktopDir + OfferLetterName
>
> If Err.Number = 5152 Then
>
> Err.Clear
> userDesktopDir = "D:\Documents And Settings\" + GetUserName +
> "\Desktop\Offer Letters\"
> firstname = ActiveDocument.FormFields("EEFName1").Result
> lastname = ActiveDocument.FormFields("EELName1").Result
> OfferLetterName = firstname + " " + lastname + " - Offer.doc"
> ActiveDocument.SaveAs FileName:=userDesktopDir +
> OfferLetterName
>
> If Err.Number = 5152 Then
> MsgBox "You must create an Offer Letters folder on your
> desktop. The wizard will no longer continue."
> ActiveDocument.ActiveWindow.Close
> SaveChanges:=wdDoNotSaveChanges
> End If
> End If
> End If
>
>
> End Sub
> ---------------------------------------------------------------------------------------------
> END CODE
>
> "Jonathan West" wrote:
>
>>
>> "axeman" <axeman@discussions.microsoft.com> wrote in message
>> news:698C29AE-3255-455C-A485-385ECA6CA2CA@microsoft.com...
>> >I have a situation. I have a Word VBA program that I am running but
>> >can't
>> > figure out how to make it work when there is already another Word
>> > document
>> > open. The userform itself will pop up but when it's supposed to
>> > transfer
>> > all
>> > the information over to a template it just sits there and does nothing.
>> > It
>> > works fine if there aren't any other open files though. If you could
>> > please
>> > provide some insight to this situation it would be of great help.
>>
>> Its impossible to give much help without seeing the relvant part of the
>> code.
>>
>>
>> --
>> Regards
>> Jonathan West - Word MVP
>> www.intelligentdocuments.co.uk
>> Please reply to the newsgroup
>> Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
>>
>>