I would like to print a .pdf file without preview. I used the "FoxitReaderOCX.ocx" component for this, but before it goes to printing, a preview is called. Is direct printing possible in this case?
My code:
Private Sub Command1_Click()
FoxitReaderOCX1.OpenFile ("C:\test_raport_PDF.pdf")
FoxitReaderOCX1.PrintFile
End Sub
I will be grateful for your help :)
Related
So i made a notepad type of software from Visual Baisc 6 and i am trying to add the text from my textbox to the Listbox. I tried to do many things but couldn't. I am not able to get to the correct code to do that.
I used list box "lstListBox" a text box "txtText" and a command button "cmdAdd"
Private Sub cmdAdd_Click()
lstListBox.AddItem txtText.Text
End Sub
this worked for me should work for you too, just like what OldBoyCoder commented hope this helps you understand better what he meant.
I have problem with button's caption in VB6.
I'm trying to change caption after "_load" event and it works, but new text is not in the center of the button - and it's a problem.
You can see it on the following screen:
https://dl.dropboxusercontent.com/u/3779161/buttons.png
I've tried to use "Refresh" function but without any effect.
Is it possible to refresh button without creating new one?
Thanks for help
I am unable to test VB6 code currently but, apparently, it requires Win-API calls to align the text. code here. Copy the code into a Module and then you can call the function AlignCommandButtonText. (Seems like hard work!)
the new text does center for me.
run the following test project and click on the form:
'1 form with
' 1 commandbutton: name=Command1 caption="Test"
Option Explicit
Private Sub Form_Click()
Command1.Caption = "New Test"
End Sub
the problem is probably caused by something else.
for example: do you have any tight loops?
could you post some of your code?
In order to use the SlideShowBegin event in Powerpoint, you have to have a Class Module configured the following way:
Public WithEvents App As Application
Private Sub App_SlideShowBegin(ByVal Wn As SlideShowWindow)
MsgBox "SlideShowBegin"
End Sub
Then, inside of a non-class module, you have to create an object of that type and set the App to Application.
Dim X As New Class1
Sub InitializeApp()
Set X.App = Application
End Sub
Now, the only issue I have is, if you don't manually called InitializeApp with the Macro Menu in Powerpoint, the events don't work. You have to call this sub before anything can called at the beginning of a slideshow INCLUDING this sub.
How can I go about calling this sub before running my powerpoint? Is there a better way to do this?
EDIT:
I've tried using Class_Initialize but it only gets called once it is first used or you make a statement like Dim X as Class1; X = new Class1
Usually event handlers are installed as part of an add-in, where you'd initialize the class in the Auto_Open subroutine, which always runs when the add-in loads. If you want to include an event handler in a single presentation, one way to cause it to init is to include a shape that, when moused over or clicked fires a macro, which inits your event handler and goes to the next slide.
Answering to an old question, but I hope my solution might helpt somebody ending up at this question.
The general advice for this issue is using a plug-in or placing some element on the slide and when that is clicked or hovered perform the initialization. Both are not always desired so I have the following approach:
In some module:
Dim slideShowRunning As Boolean
-----------------------------
Sub SlideShowBegin(ByVal Wn As SlideShowWindow)
' Your code for start-up
End Sub
-----------------------------
Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
If TypeName(slideShowRunning) = "Empty" Or slideShowRunning = False Then
slideShowRunning = True
SlideShowBegin Wn
End If
End Sub
----------------------------
Public Sub OnSlideShowTerminate(ByVal Wn As SlideShowWindow)
slideShowRunning = False
End Sub
For me this works perfectly. NOTE I am by no means a vba expert, actually I might have less than 50 hours of vba programming (maybe only 8 in powerpoint). So this might be an horrible solution. I don't know, but for me it works so I liked to share.
In fact, OnSlideShowPageChange runs when slideshow begins. Just make sure it doesn't work in the subsequent page changes if not needed using a global variable. See answer from C. Binair for details.
I am trying to Save an Excel file Via VB 2010, and I have these questions
How can I disable the "save as" dialog? I tried things such as only "save" instead of "save as", but it doesen't work...
After I saved the file (using the save as) I can't Delete it... (I tried closing the excel file, Visual basic etc...) all i get is an error saying it is allready open in excel...
Is there a way to make VB show me the tips for writing the excel stuff (Ie - when I write messagebox. - it pops up "Show" for help. how can I enable this for excel code [worksheets.cells. ect.])
the connection:
Sub Connect()
' Connect to the excel file
oExcel = CreateObject("Excel.Application")
'Devine the workbook
oBook = oExcel.workbooks.open("e:\Words\Heb.xls")
End Sub
the saveas:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
oExcel.SaveAs(oExcel.Path & ".xls")
End Sub
Thanks a lot
I think Inafiziger has solved your main issue, it should be a vanilla Save.
As it was unclear to me exactly what your are doind (ie Visual Studio/VB/BA) then
On (1)
I thought it worth clarifying that you can use code inside the ThisWorkbook module to detect and handle a SaveAs if you are providing users with a choice. This Event detects the SaveAs and cancels it
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
MsgBox "You cannot use SaveAs to save this file", , "Save Cancelled!"
Cancel = True
End If
End Sub
This code can be programmatically added to your target workbook but I doubt you would need to resort to this given you should be able to run the simple Save.
On (3)
You need to use Early Binding to get the benefit of intellisense. You are currently use late binding with oExcel = CreateObject("Excel.Application"). A commonly used approach is to write the code and get it working with early binding, then converting it to late binding for final code publication.
Conditional Compilation (see comment at bottom) can be used to switch between the two binding methods within the same code.
You should be saving the workbook. e.g. oBook.Save.
If you create a new file, you will need to use SaveAs with a valid filename in order to save it the first time.
I have a VB.net test application that clicks a link that opens the Microsoft Word application window and displays the document. How do I locate the Word application window so that I can grab some text from it?
You can use the Word COM object to open the work document and then you manipulate it. Make sure to add a reference for Microsoft Word first.
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.Word
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strFileName As String
Dim wordapp As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document
Try
doc = wordapp.Documents.Open("c:\testdoc.doc")
doc.Activate()
Catch ex As COMException
MessageBox.Show("Error accessing Word document.")
End Try
End Sub
End Class
The doc object is a handle for the instance of Word you have created and you can use all the normal options (save, print etc). You can do likewise with the wordapp. A trick is to use the macro editor in Word to record what you want to do. You can then view this in the Macro Editor. This give you a great starting point for your VB code.
Also, be sure to dispose of the Word COM objects at the end.
I've done something similar with a SourceSafe dialog, which I posted on my blog. Basically, I used either Spy++ or Winspector to find out the window class name, and make Win32 calls to do stuff with the window. I've put the source on my blog: http://harriyott.com/2006/07/sourcesafe-cant-leave-well-alone.aspx
Are you trying to activate the word app? If you want full control, you need to automate word from your vb.net app. Check here for some samples: 1, 2