Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > Error 4248 from file on intranet


Reply
 
Thread Tools Display Modes
  #1  
Old 06-25-2012, 03:08 AM
KenZu KenZu is offline
Newcomer
 
Join Date: Jun 2012
Posts: 2
Question Error 4248 from file on intranet


Hello. Im new here and a newbie on VB.
I got like 100+ documents (word 2007 and excel 2007) and the main thing will be, to have the opportunity to choose a footer when you open a doc from a popup. im this case, three different offices.
All documents will be on our intranet.

But... When I'm trying to open a file (from intranet), Im getting error 4248 - "The command is not avaliable because no document is open".
But it works when im open it direct from our server.

What is wrong with my code below?

This is my code:
Code:
Private Sub Document_New()
Call Document_Open
End Sub

Private Sub Document_Open()
Application.ScreenUpdating = False
Dim Rng As Range, Str As String, Fld As Field, i As Long
i = CLng(InputBox("Which Office?" & vbCr & "1: Gothenburg, 2: Stockholm, 3: Malmö"))
If i = 0 Or i > 3 Then Exit Sub
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
Set Rng = .Range.Characters.First
Rng.Collapse wdCollapseStart
For Each Fld In .Range.Fields
With Fld
If .Type = wdFieldQuote Then
Set Rng = Fld.Result
.Delete
Exit For
End If
End With
Next
Select Case i
Case 1
Str = "Gothenburg AB, Tel 010-123456, www.gothenburg.com"
Case 2
Str = "Stockholm AB, Tel 010-123456, www.stockholm.com"
Case 3
Str = "Malmö AB, Tel 010-123456,www.malmö.com"
End Select
Set Fld = ActiveDocument.Fields.Add(Range:=Rng, Type:=wdFieldQuote, _
Text:="""" & Str & """", PreserveFormatting:=False)
End With
Set Fld = Nothing: Set Rng = Nothing
Application.ScreenUpdating = True
End Sub

Last edited by Flyguy; 06-25-2012 at 04:12 AM.
Reply With Quote
  #2  
Old 06-25-2012, 04:42 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Error 4248

Hello KenZu and welcome to the forum.

We strongly encourage forum members to do a little research before posting their question(s).

If you had you might have been able to reference this MSDN document
regarding error 4248 when using vba with Word 2007 documents:
You receive run-time error 4248, 4605 or 5941 when you try to change properties on an unopened document in Word
Quote:
This problem may occur if you do not have a document open,
or if the document that you are referencing is not open.
Word can only change the properties of an open (or visible) document.
Note These error messages may also appear if you open the document
with the Visible property set to False.
If you searched the xvbt forum you would have found these two threads regarding error 4248:
ActiveDocument errors
New Word Doc

You might also have found this interesting (perhaps relevant) Google groups thread:
How to avoid Runtime error 4248

The general gist of the thread is that timing is important.
If the file is on an intranet there maybe a latency issue.
You might try some error trapping and possible tack on a sleep command to see if this is the case.

Of course addins can also assist generate this error so
you may want to turn off all add-ins and macros attached to the word documents before trying this..

Last edited by surfR2911; 06-25-2012 at 04:49 PM.
Reply With Quote
  #3  
Old 06-26-2012, 12:03 AM
KenZu KenZu is offline
Newcomer
 
Join Date: Jun 2012
Posts: 2
Default

Thx for your answer.
I did some search, both on the website and google, but newbie as I am, I didnt understood what to add and what to change/delete in the script.

Hoped that someone could help me with my specific code
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->