+ Reply to Thread
Results 1 to 4 of 4

Stuck with VBA Code. Creating a unique reference number with each macro click

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-12-2014
    Location
    Reading
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20176) 64-bit
    Posts
    138

    Stuck with VBA Code. Creating a unique reference number with each macro click

    Hi,

    I have an export to Word macro. I want to achieve more with is but my skills are limited so if you could help I'd be forever grateful.

    The code is below.

    Private Sub Quote_Click()
    Dim WdObj As Object, fname As String
    fname = Sheets(2).[a1].Value
    Set WdObj = CreateObject("Word.Application")
    WdObj.Visible = False
    Selection.Copy 'Your Copy Range
    WdObj.documents.Add
    WdObj.Selection.PasteSpecial Link:=False, _
        DataType:=wdPasteText, Placement:= _
        wdInLine, DisplayAsIcon:=False
    Application.CutCopyMode = False
    If fname <> "" Then 'make sure fname is not blank
    With WdObj
        .ChangeFileOpenDirectory "F:\Aacommon\Joe Signs\Quotes" 'save Dir
        .ActiveDocument.SaveAs Filename:=fname & ".doc"
    End With
    Else:
    MsgBox ("File not saved, naming range was botched, guess again.")
    End If
    With WdObj
        .ActiveDocument.Close
        .Quit
    End With
    Set WdObj = Nothing
    End Sub
    What I would like to achieve is a unique reference number (URN) generated each time the macro button is clicked, that number entered in a specified cell within the sheet and then the file saved as that reference number.

    Can anyone help me achieve that?

    Also, how would I specify what needs to be exported? For example, I currently have to select the area I want to export and then click the button. I need it to export columns A to J and Rows 1 to 50.

    Thanks in advance.

    Edit: Apologies for not complying with the rules.
    Last edited by blackburnsexcel; 11-27-2014 at 08:49 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,455

    Re: Need a challenge? Help me with VBA code?

    Tags added
    Last edited by Pepe Le Mokko; 11-28-2014 at 05:01 AM.

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,455

    Re: Need a challenge? Help me with VBA code?

    Title much more clear
    Last edited by Pepe Le Mokko; 11-28-2014 at 05:01 AM.

  4. #4
    Forum Contributor
    Join Date
    11-12-2014
    Location
    Reading
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2403 Build 16.0.17425.20176) 64-bit
    Posts
    138

    Re: Stuck with VBA Code. Creating a unique reference number with each macro click

    I've found another piece of code that may acheive what I'm looking for but I wouldn't know how to integrate it.

    Option Explicit 
     
    Sub Increment() 
        Dim lNum As Long 
         
        lNum = Cells(1, 1).Value 'A1 change to suit
         'first check that a number is entered
        If Cells(1, 1).Value = "" Then 
            lNum = 1 
            Cells(1, 1).Value = lNum 
        Else: Cells(1, 1).Value = lNum + 1 
        End If 
    End Sub

+ 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. Quran Code Challenge – Fake or Real??!
    By pouradam in forum The Water Cooler
    Replies: 7
    Last Post: 04-22-2024, 09:41 PM
  2. A Challenge:Extend Code of a button to remove the Formula of the Saved Page and lock
    By ronettes in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2014, 06:01 AM
  3. Community Code Challenge Login
    By Kieran in forum ExcelTip.com Feedback / Comments / Suggestions
    Replies: 1
    Last Post: 11-28-2008, 03:27 PM
  4. [SOLVED] Challenge of the day: linking VBA code to combo box selections
    By Todd in Dayton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 01:50 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