Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  2.  
  3. If Not Application.Intersect(Target, Range("AG4:AG910")) Is Nothing Then
  4. Dim FileNames As Variant
  5. Dim Msg As String
  6. Dim i As Integer
  7. FileNames = Application.GetOpenFilename(MultiSelect:=True)
  8. If IsArray(FileNames) Then
  9. For i = LBound(FileNames) To UBound(FileNames)
  10. Msg = Msg & FileNames(i) & vbNewLine
  11. Next i
  12. Target = Msg
  13. Else
  14. MsgBox "No files were selected."
  15. End If
  16.  
  17. End If
  18.  
  19. function onOpen() {
  20.  
  21. SpreadsheetApp.getUi()
  22. .createMenu('Custom Menu')
  23. .addItem('Show Upload Dialog', 'showUploadBox')
  24. .addToUi();
  25. };
  26.  
  27. function showUploadBox() {
  28.  
  29. var htmlOutput = HtmlService.createHtmlOutputFromFile('Dialog')
  30. .setWidth(500)
  31. .setHeight(500);
  32.  
  33. SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Title of Dialog');
  34. };
  35.  
  36. <div id="formDiv">
  37.  
  38. <form id="myForm">
  39.  
  40. <input id="fileName" name="picToLoad" type="file" />
  41. <br>
  42. <br/>
  43. <input type="button" value="Submit" onclick="fncGetFileName()" />
  44. <br>
  45. <br>
  46. <br>
  47. <input id="idBtnClose" type="button" value="Close" style="display: none" onclick="google.script.host.close()" />
  48. </form>
  49. </div>
  50.  
  51. <br>
  52. <br>
  53.  
  54. <div id="status" style="display: none">
  55. <!-- div will be filled with innerHTML after form submission. -->
  56. Working. Please wait...
  57. </div>
  58.  
  59.  
  60. <script>
  61.  
  62. function fncGetFileName(frmData) {
  63. console.log('fncGetFileName ran!');
  64.  
  65. var theFileName = document.getElementById('fileName').value;
  66. theFileName = theFileName.slice(12);
  67.  
  68. console.log('theFileName: ' + theFileName);
  69.  
  70. document.getElementById('status').style.display = 'inline'; //Display msg
  71.  
  72. google.script.run
  73. .withSuccessHandler(updateOutput)
  74. .processForm(theFileName)
  75. };
  76. // Javascript function called by "submit" button handler,
  77. // to show results.
  78.  
  79. function updateOutput() {
  80.  
  81. var outputDiv = document.getElementById('status');
  82. outputDiv.innerHTML = "The File Name was Written!";
  83.  
  84. document.getElementById('idBtnClose').style.display = 'inline'; //Display msg
  85. }
  86.  
  87. </script>
  88.  
  89. function processForm(argFileName) {
  90. Logger.log('argFileName: ' + argFileName);
  91.  
  92. var ss = SpreadsheetApp.getActiveSpreadsheet();
  93. var theSheet = ss.getActiveSheet();
  94.  
  95. var theRange = theSheet.getRange("B4");
  96. theRange.setValue(argFileName);
  97. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement