Error 4160 Bad File Name
Contents |
(Русский)ישראל (עברית)المملكة العربية السعودية (العربية)ไทย (ไทย)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語) HomeLibraryLearnDownloadsForums Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Asked by: bad filename or number vba VBA Runtime Error 4160 "Bad file name" when using Document.fullname bad filename or number access import as index Microsoft Office for Developers > Word for Developers General discussion 0 Sign in access 2010 bad filename or number to vote One of my macros runs the following statement: Documents(ThisDocument.FullName).UndoClear (Edit in response to Cindy's first comment below: The actual macro does the UndoClear bad filename or number vbscript on a document which is passed as a parameter to the routine which executes it. I used 'ThisDocument' in the example to provide a simple illustration and means of reproducing the underlying problem). It works fine if ThisDocument is on a local or a network drive, but if on a SkyDrive
Runtime Error 52 Bad Filename Or Number Fix
or SharePoint equivalent (as is the case, for example, on my personal SkyDrive or on the Office 365 that comes with my MSDN subscription), it raises a Runtime Error 4160 "Bad File name". The problem can be reproduced as follows: 1. Store a document on SkyDrive that contains the following macro: Sub showProblem() MsgBox "Press OK to continue" Documents(ThisDocument.FullName).UndoClear End Sub 2. Open the document from SkyDrive, and choose to Edit it using your local Word. 3. Run the macro. I have circumvented the problem as follows: 1. A new function finds the numeric index given a FullName: Function BWordGetNumericDocumentIndex(xFullName As String) As Long On Error GoTo notOpen Dim i As Long For i = 1 To Documents.Count If Documents(i).FullName = xFullName Then BWordGetNumericDocumentIndex = i Exit Function End If Next i notOpen: BWordGetNumericDocumentIndex = -1 'in case of failure End Function 2. Where required, replace "Documents(ThisDocument.FullName)" with "Documents(BWordGetNumericDocumentIn
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Modify an opened word document https://social.msdn.microsoft.com/Forums/silverlight/en-US/b1198baa-8be2-4640-ba35-050ba7c6d0a2/vba-runtime-error-4160-bad-file-name-when-using-documentfullname-as-index?forum=worddev through Excel up vote 0 down vote favorite How can I modify an opened word document through Excel with VBA? Here a bit of code I'm writing, but there's something wrong I can't understand. Dim WordDoc As Word.Document Dim WordApp As Word.Application 'ThisWorkbook is the opened Excel Workbook through which I control Word documents. If Len(Dir(ThisWorkbook.path & "\Report.docx")) <> 0 then 'if the document exists in http://stackoverflow.com/questions/24539104/modify-an-opened-word-document-through-excel the folder where ThisWorkbook is saved, I check 'if the document is already opened. If IsFileOpened(ThisWorkbook.path & "\Report.docx") 'if during the run-time I get here, it means that the document exists and 'it's already opened. 'Now I want to get the reference to the opened document "Report.docx", 'so I do a thing like this. Set WordDoc= Word.Application.Documents(ThisWorkbook.path & "\Report.docx") 'When it tries to excute the instruction over, it gives me a message in which 'it is written that the name is bad or inexistent, even if the document 'is already opened. Is the instruction correct? Set WordApp= WordDoc.Application '...other code Else 'if the document isn't opened, I open it. Set WordApp = CreateObject("Word.Application") Set WordDoc = WordApp.Documents.Open(ThisWorkbook.path & "\Report.docx") '..other code End If Else 'I create a new document called "Report.docx" if it doesn't exist 'in the folder where ThisWorkbook is saved. Set WordApp = CreateObject("Word.Application") Set WordDoc = WordApp.Documents.Add("Report.docx") '.... other code End If Thanks in advance... excel vba ms-word share|improve this question edited Jul 3 '14 at 6:15 KazimierzJawor 14.2k61736 asked Jul 2 '14 at 19:05 Sara19 185 On which line does it break? –Julien Marrec Jul 2 '14 at 19:
has me stumped. I have started getting a Run-time error '4160' - bad file name in http://www.office-forums.com/threads/4160-bad-file-name.1862364/ a macro that was working fine yesterday and for the past 3 years!!!! I am running in W2K server and word 2002. This is the code that causes the problem and https://groups.google.com/d/topic/microsoft.public.word.vba.general/1Obe_YZLtvM is part of autoOpen DocPath = DocDrive & DocDir & "\" & DocFile Set prop = ActiveDocument.BuiltInDocumentProperties prop(wdPropertyHyperlinkBase) = DocDrive & DocDir Application.Documents(DocPath).Saved = True The actual line that causes bad file the problem is the last line Application.Documents(DocPath).Saved = True I checked and double checked the path and it is correct. I also recreated the normal.dot file to no avail. I can make changes to the DocPath file. Any suggestions would be dearly appreciated. Thank you in advance. Regards, Buta Buta Singh, Jul 28, 2003 #1 Advertisements Word Heretic Guest bad filename or G'day "Buta Singh" <>, the contents of DocPath are ok when it breaks? "Buta Singh" <> was spinning this yarn: >Hello > >I have a situation that has me stumped. I have started >getting a Run-time error '4160' - bad file name in a >macro that was working fine yesterday and for the past 3 >years!!!! I am running in W2K server and word 2002. This >is the code that causes the problem and is part of >autoOpen > > DocPath = DocDrive & DocDir & "\" & DocFile > Set prop = ActiveDocument.BuiltInDocumentProperties > prop(wdPropertyHyperlinkBase) = DocDrive & DocDir > Application.Documents(DocPath).Saved = True > >The actual line that causes the problem is the last line >Application.Documents(DocPath).Saved = True > >I checked and double checked the path and it is correct. I >also recreated the normal.dot file to no avail. I can make >changes to the DocPath file. > >Any suggestions would be dearly appreciated. Thank you in >advance. > >Regards, > >Buta Steve Hudson Word Heretic, Sydney, Australia Tricky stuff with Word or words for you. Email: Products: http://www.geocities.com/w
von GoogleAnmeldenAusgeblendete FelderNach Gruppen oder Nachrichten suchen