Проблема рассосалась совершенно неожиданным образом. Оказалось, проблема не xltm, a xlsb. После пересохранения xlsb - xlsm - xltm все стало работать. Но возникла другая - при запуске шаблона на работает [vba]
Код
.InitialFileName = ThisWorkbook.Path
[/vba] ввиду отсутствия последнего. Как бы здесь исхитриться?
Проблема рассосалась совершенно неожиданным образом. Оказалось, проблема не xltm, a xlsb. После пересохранения xlsb - xlsm - xltm все стало работать. Но возникла другая - при запуске шаблона на работает [vba]
Код
.InitialFileName = ThisWorkbook.Path
[/vba] ввиду отсутствия последнего. Как бы здесь исхитриться?RAN
Короче, задал ты головоломку Второй день ищу решение через апи. Все, что есть на данный момент: [vba]
Код
Private Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassname As String, ByVal nMaxCount As Long) As Long Private Declare Function apiGetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long Private Declare Function apiGetWindow Lib "user32" Alias "GetWindow" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long Private Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function apiGetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal aint As Long) As Long
Function fEnumWindows() Dim lngx As Long, lngLen As Long Dim lngStyle As Long, strCaption As String
lngx = apiGetDesktopWindow() 'Return the first child To Desktop lngx = apiGetWindow(lngx, mcGWCHILD) Do While Not lngx = 0 strCaption = fGetCaption(lngx) If Len(strCaption) > 0 Then lngStyle = apiGetWindowLong(lngx, mcGWLSTYLE) 'enum visible windows Only If lngStyle And mcWSVISIBLE Then Debug.Print "Class = " & fGetClassName(lngx), Debug.Print "Caption = " & fGetCaption(lngx) End If End If lngx = apiGetWindow(lngx, mcGWHWNDNext) Loop End Function
Private Function fGetClassName(Hwnd As Long) Dim strBuffer As String Dim intCount As Integer
strBuffer = String$(mconMAXLEN - 1, 0) intCount = apiGetClassName(Hwnd, strBuffer, mconMAXLEN) If intCount > 0 Then fGetClassName = Left$(strBuffer, intCount) End If End Function
Private Function fGetCaption(Hwnd As Long) Dim strBuffer As String Dim intCount As Integer
strBuffer = String$(mconMAXLEN - 1, 0) intCount = apiGetWindowText(Hwnd, strBuffer, mconMAXLEN) If intCount > 0 Then fGetCaption = Left$(strBuffer, intCount) End If End Function
Sub Fooad() Call fEnumWindows End Sub
[/vba]
Даст заголовки и класс запущенных видимых окон. Может получится что-нибудь допилить.
Если повесить на открытие книги, то сразу за окном экселя в списке получишь заголовок окна проводника, из которого был запуск файла.
Короче, задал ты головоломку Второй день ищу решение через апи. Все, что есть на данный момент: [vba]
Код
Private Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA" (ByVal Hwnd As Long, ByVal lpClassname As String, ByVal nMaxCount As Long) As Long Private Declare Function apiGetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Long Private Declare Function apiGetWindow Lib "user32" Alias "GetWindow" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long Private Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function apiGetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal aint As Long) As Long
Function fEnumWindows() Dim lngx As Long, lngLen As Long Dim lngStyle As Long, strCaption As String
lngx = apiGetDesktopWindow() 'Return the first child To Desktop lngx = apiGetWindow(lngx, mcGWCHILD) Do While Not lngx = 0 strCaption = fGetCaption(lngx) If Len(strCaption) > 0 Then lngStyle = apiGetWindowLong(lngx, mcGWLSTYLE) 'enum visible windows Only If lngStyle And mcWSVISIBLE Then Debug.Print "Class = " & fGetClassName(lngx), Debug.Print "Caption = " & fGetCaption(lngx) End If End If lngx = apiGetWindow(lngx, mcGWHWNDNext) Loop End Function
Private Function fGetClassName(Hwnd As Long) Dim strBuffer As String Dim intCount As Integer
strBuffer = String$(mconMAXLEN - 1, 0) intCount = apiGetClassName(Hwnd, strBuffer, mconMAXLEN) If intCount > 0 Then fGetClassName = Left$(strBuffer, intCount) End If End Function
Private Function fGetCaption(Hwnd As Long) Dim strBuffer As String Dim intCount As Integer
strBuffer = String$(mconMAXLEN - 1, 0) intCount = apiGetWindowText(Hwnd, strBuffer, mconMAXLEN) If intCount > 0 Then fGetCaption = Left$(strBuffer, intCount) End If End Function
Sub Fooad() Call fEnumWindows End Sub
[/vba]
Даст заголовки и класс запущенных видимых окон. Может получится что-нибудь допилить.
Если повесить на открытие книги, то сразу за окном экселя в списке получишь заголовок окна проводника, из которого был запуск файла.
Private Sub Workbook_BeforeClose(Cancel As Boolean) 10 If Me.Saved = False Then 20 If Len(Me.ActiveSheet.Cells(2, 2)) Then 30 Call Save_as 40 End If 50 End If 60 Me.Saved = True End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 10 If Len(Me.ActiveSheet.Cells(2, 2)) Then 20 Call Save_as 30 If Me.Saved = False Then Cancel = True 40 End If End Sub
Private Sub Workbook_Open() 10 Call comparison_calculations End Sub Private Sub Save_as() Dim Filename 10 With Application.FileDialog(msoFileDialogSaveAs) 20 .InitialFileName = ThisWorkbook.Path & "\" & "Сравнение" 30 If .Show = 0 Then Exit Sub 40 ThisWorkbook.ActiveSheet.Copy 50 Application.DisplayAlerts = False 60 .Execute 70 Application.DisplayAlerts = True 80 End With 90 ActiveWorkbook.Close False 100 ThisWorkbook.Saved = True 110 ThisWorkbook.Close False
End Sub
[/vba]
Круто!
Мы пошли другим путем!
Сделал xlsm с кодом
[vba]
Код
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean) 10 If Me.Saved = False Then 20 If Len(Me.ActiveSheet.Cells(2, 2)) Then 30 Call Save_as 40 End If 50 End If 60 Me.Saved = True End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 10 If Len(Me.ActiveSheet.Cells(2, 2)) Then 20 Call Save_as 30 If Me.Saved = False Then Cancel = True 40 End If End Sub
Private Sub Workbook_Open() 10 Call comparison_calculations End Sub Private Sub Save_as() Dim Filename 10 With Application.FileDialog(msoFileDialogSaveAs) 20 .InitialFileName = ThisWorkbook.Path & "\" & "Сравнение" 30 If .Show = 0 Then Exit Sub 40 ThisWorkbook.ActiveSheet.Copy 50 Application.DisplayAlerts = False 60 .Execute 70 Application.DisplayAlerts = True 80 End With 90 ActiveWorkbook.Close False 100 ThisWorkbook.Saved = True 110 ThisWorkbook.Close False