+ Reply to Thread
Results 1 to 2 of 2

Save doc file as per text in the document

Hybrid View

  1. #1
    Registered User
    Join Date
    05-27-2015
    Location
    Zagreb
    MS-Off Ver
    2010
    Posts
    36

    Save doc file as per text in the document

    Dear all,

    I would appreciate your help with following:

    Attached doc file should be saved as 12345678912.docx

    I had in mind function MID, but I can't get it to work properly. Most probable because there are more lines in this cell.

    Thank you,
    t.

    ip1 only find and save.docx

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Save doc file as per text in the document

    You could use this code:
    Sub Macro1()
       Dim myText As String, p1 As Long
       Dim p2 As Long, p3 As Long, idNum As String
       
       Application.DisplayAlerts = wdAlertsNone
       myText = ActiveDocument.Range
       p1 = InStr(myText, "II. PODACI ")
       p2 = InStr(p1, myText, "3. Osobni identifikacijski broj")
       p3 = InStr(p1, myText, "4. IBAN")
       idNum = Trim(Replace(Mid(myText, p2 + 31, p3 - p2 - 33), vbTab, ""))
       
       ActiveDocument.SaveAs2 FileName:=idNum & ".docx", _
                FileFormat:=wdFormatXMLDocument, LockComments:=False, _
                Password:="", AddToRecentFiles:=True, WritePassword:="", _
                ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
                SaveNativePictureFormat:=False, SaveFormsData:=False, _
                SaveAsAOCELetter:=False, CompatibilityMode:=14
       
       
       Application.DisplayAlerts = wdAlertsAll
    End Sub
    Regards,
    Antonio

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Document to save as a PDF file and not a xls using a Macro
    By Riazy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-23-2014, 07:27 PM
  2. Macro to save text string as an MS-DOS format text document
    By bwink88 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-16-2013, 02:25 PM
  3. How to save the opened word document as a Notepad/text file?
    By Rahul888 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-10-2012, 05:38 PM
  4. Save worksheet to document file name
    By fb2003 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-04-2008, 04:29 PM
  5. [SOLVED] 'document not saved' for 'save' or 'save as' an EXCEL file
    By Judy Chuang in forum Excel General
    Replies: 1
    Last Post: 07-11-2005, 06:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1