Just some slight changes to Brent's code will do what you want.
I added arguments for the table, backend name and backend file extension.
Code:
Public Sub BackUpAndCompactBE(vTable As String, BEName As String, FType As String)
'vTable is the name of a table in your backend
'BEName is the name for the saved backend
'FType is the file type of the backend ie. Accdb or Mdb
'Courtesy of Brent Spaulding (datAdrenaline), MVP
'Modified by theDBguy on 5/27/2019
'Source: http://www.accessmvp.com/thedbguy
On Error GoTo errHandler
Dim oFSO As Object
Dim strDestination As String
Dim strSource As String
Dim strTableName As String
Dim strFileName As String
strTableName = vTable 'name of your linked table
strFileName = "\" & BEName 'name of your backup file
'Get the source of your back end
strSource = Split(Split(CurrentDb.TableDefs(strTableName).Connect, _
"Database=")(1), ";")(0)
'Determine your destination
strDestination = CurrentProject.Path & strFileName & "." & FType '" (" _
' & Format(Now, "yyyymmddhhnnss") & ").accdb"
'Flush the cache of the current database
DBEngine.Idle
'Create a file scripting object that will backup the db
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.CopyFile strSource, strDestination
Set oFSO = Nothing
'Compact the new file, ...
Name strDestination As strDestination & ".cpk"
DBEngine.CompactDatabase strDestination & ".cpk", strDestination
'Uncomment the following line and comment the previous line
'if your backend file is password protected or if you want the backup to have a password
'DBEngine.CompactDatabase strDestination & ".cpk", strDestination, , , ";pwd=YourPassword"
Kill strDestination & ".cpk"
'Notify users
MsgBox "Backup file '" & strDestination & "' has been created.", _
vbInformation, "Backup Completed!"
errExit:
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
Resume errExit
End Sub