View Single Post
 
Old 09-14-2017, 05:21 AM
nolanthomas32 nolanthomas32 is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Sep 2017
Posts: 3
nolanthomas32 is on a distinguished road
Default

Thank you for your reply Macropod. This is actually a modified version of the code you provided to someone else in the forums.
Code:
Sub Export_Click()
Dim xlApp As New Excel.Application, xlWkBk As Excel.Workbook, xlWkSht As Excel.Worksheet, r As Long
With xlApp
  'Hide our Excel session
  .Visible = True 'False
  'Open the workbook
  Set xlWkBk = .Workbooks.Open("C:\Users\nithomas\OneDrive - UNCG\Autofill Database Test 4.xlsx", AddToMRU:=False)
  Set xlWkSht = xlWkBk.Sheets("Master Database")
  'Find the next available row
  r = xlWkSht.UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Row + 1
  'Update the workbook
  With ActiveDocument
    xlWkSht.Range("B" & r).Value = .SelectContentControlsByTitle("Student Name")(1).Range.Text
    xlWkSht.Range("C" & r).Value = .SelectContentControlsByTitle("PID Concentration")(1).Range.Text
    xlWkSht.Range("D" & r).Value = .SelectContentControlsByTitle("Second Degree")(1).Range.Text
    xlWkSht.Range("E" & r).Value = .SelectContentControlsByTitle("First Degree")(1).Range.Text
    xlWkSht.Range("F" & r).Value = .SelectContentControlsByTitle("Associates of Arts")(1).Range.Text
    xlWkSht.Range("G" & r).Value = .SelectContentControlsByTitle("Associates of Applied Science")(1).Range.Text
    xlWkSht.Range("H" & r).Value = .SelectContentControlsByTitle("Bachelor of Arts")(1).Range.Text
    xlWkSht.Range("I" & r).Value = .SelectContentControlsByTitle("Master of Arts")(1).Range.Text
    xlWkSht.Range("J" & r).Value = .SelectContentControlsByTitle("Doctor of Philosophy")(1).Range.Text
    xlWkSht.Range("K" & r).Value = .SelectContentControlsByTitle("Other")(1).Range.Text
 End With
  ' Save & Close the Excel workbook
  xlWkBk.Close SaveChanges:=True
  .Quit
End With
' Release object memory
Set xlWkSht = Nothing: Set xlWkBk = Nothing: Set xlApp = Nothing
' Tell the user we're done.
MsgBox "Workbook updates finished.", vbOKOnly
End Sub
The content control "PID Concentration" is the one that I am trying to have designate which sheet it exports to in the excel book. Right now there are three drop down options for that control. "K-12 Deaf and Hard of Hearing Teaching Licensure" "Advocacy and Services for the Deaf" & "Interpreter Preparation".

Thank you!

Last edited by macropod; 09-14-2017 at 02:55 PM. Reason: Added code tags
Reply With Quote